简体   繁体   中英

Got “-std=c++11: command not found” error when trying to compile a object file using g++

As in the title, when I try to compile an object file using g++ by running this shell script:

#!/bin/bash
name=textsweeper
srcdir=src
buildir=build
cc=g++
cppflags=-Wall -std=c++11 -ggdb -O
libs=
rm -f $buildir/$name $buildir/main.o
$cc $cppflags $srcdir/main.cpp -c -o $buildir/main.o
$cc $buildir/main.o $libs -o $buildir/$name

I get the following error:

$ bash compile
compile: line 6: -std=c++11: command not found

And other errors about things being only available only with stdc++11. I've tried yahooing the error, but I've only got answers to about errors about actual command not arguments.

Variable assignment is space sensitive. Change:

cppflags=-Wall -std=c++11 -ggdb -O

to

cppflags="-Wall -std=c++11 -ggdb -O"

Otherwise, you're trying to run the command -std=c++11 -ggdb -O with the environment including a setting of cppflags=-Wall . bash allows temporary environment settings to be done this way, which is why its important to quote any variable assignments that contain spaces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM