【发布时间】:2015-10-20 04:28:44
【问题描述】:
我可以编辑默认的 makefile 吗?我想将-std=c++11 标志添加到默认makefile 中,以便make 命令编译和构建C++11 程序。
例如,目前,当我尝试使用make 命令编译程序时,会出现以下错误:
g++ a.cpp -o a
a.cpp: In function ‘int main()’:
a.cpp:118:12: error: ISO C++ forbids declaration of ‘it’ with no type [-fpermissive]
for(auto &it : v) cout << it << endl;
^
a.cpp:118:17: warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11
for(auto &it : v) cout << it << endl;
^
<builtin>: recipe for target 'a' failed
make: *** [a] Error 1
【问题讨论】:
-
打开
Makefile并将您的标志添加到CPPFLAGS变量(如果存在)。但大多数 Makefile 都有这些变量 -
在哪里可以找到makefile?我不写任何makefile,我只是在终端中运行“make a”,其中a.cpp是文件名..
-
那么
Makefile应该在你调用make的同一个目录中。 -
其实我在问如何编辑默认makefile,可以使用“make -p -f /dev/null”查看
-
没有“默认生成文件”。内置规则称为内置规则,因为它们是内置的。如果你真的需要的话,你可以下载 gnu make 的源代码并修改它。否则,在您的源目录中创建一个makefile,然后将
CPPFLAGS += -std=c++11放入其中,内置规则将使用它。