【发布时间】:2017-01-07 17:19:40
【问题描述】:
如标题所示,当我尝试通过运行此 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 中可用的东西的错误。 我试过雅虎错误,但我只得到关于实际命令而不是参数的错误的答案。
【问题讨论】:
-
顺便说一下,考虑使用 GNU Make 之类的东西。
-
@LightnessRacesinOrbit 我试过了,但我认为 Makefile 过于复杂。
-
在您的项目中添加少量内容后,不会像这个 shell 脚本那样过于复杂。
-
@digitcrusher 是的,它们对于非平凡的项目来说过于复杂了。不久之后,您的 bash 脚本也会出现同样的情况。您不想手动编写此类文件。您想自动生成它们。查看CMake 了解在 C++ 世界中广泛使用的构建系统。
标签: c++ linux bash variables gcc