c++ - 尝试使用 g++ 编译目标文件时出现 "-std=c++11: command not found"错误

标签 c++ linux bash variables gcc

如标题所示,当我尝试通过运行此 shell 脚本使用 g++ 编译目标文件时:

#!/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

我收到以下错误:

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

以及其他有关仅适用于 stdc++11 的内容的错误。 我试过 yahooing 错误,但我只得到了关于实际命令错误的答案,而不是参数。

最佳答案

变量赋值是空间敏感的。变化:

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

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

否则,您将尝试在包含 cppflags=-Wall 设置的环境中运行命令 -std=c++11 -ggdb -O。 bash 允许以这种方式完成临时环境设置,这就是为什么引用任何包含空格的变量赋值很重要。

关于c++ - 尝试使用 g++ 编译目标文件时出现 "-std=c++11: command not found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41524259/

相关文章:

c++ - 如何在函数调用后初始化变量,就像 new 表达式提供的那样?

linux - 时间戳计数器

c++ - 如何在不使用 argv 和 argc 的情况下将总和值传递给 C++ 程序

bash - 无限 Bash 历史

c++ - 为什么这个函数不会计算超过 10 位数字?

c++ - 通过boost::lexical_cast添加类型进行转换(segfault)

c++ - 删除链表

linux - 重新激活 python 脚本 - Linux bash 脚本

php - PHP 中的 While 循环,位于 shell 脚本内

string - 如何防止 vim 在字符串中添加缩进?