问题描述
我能够使用gcc和-std = c ++ 0x选项编译单个文件。但我不能这样做通过makefile。这里是我的makefile中的标志集(其中后,抱怨关于c ++ 11关键字):
MACHINE = $ shell echo`uname -s`-`uname -m` | seds / // g)
CCC = CC
CCC = g ++
CFLAGS = -O3
CFLAGS = -std = c ++ 0x
CFLAGS = -pg -D_DEBUG -g -c -Wall
LFLAGS = -O
LFLAGS = -pg -g
我缺少什么?
编辑
我把它改成了以下,但是我仍然得到编译错误,我不能通过命令行gcc调用。CXXFLAGS = -O3 -std = c ++ 0x -pg -D_DEBUG -g -c -Wall
解决方案这样你的makefile将使用你所有的
CFLAGS
:CFLAGS = -O3 -std = c ++ 0x -pg -D_DEBUG -g -c -Wall
您正在使用每个CFLAGS = ...声明覆盖它们。
此外, c $ c> CXXFLAGS ,而不是
CFLAGS
。CFLAGS
适用于C应用程式。
正如@Florian Sowade所说,您可以使用
CFLAGS + = -O3 -std ....
(或CXXFLAGS ..),以便用户可以在执行make时提供自己的标志。I am able to compile a single file using gcc with -std=c++0x option. But I can't do this through makefile. Here are the set of flags in my makefile (which after make complains about c++11 keywords):
MACHINE = $(shell echo `uname -s`-`uname -m` | sed "s/ //g") CCC = CC CCC = g++ CFLAGS = -O3 CFLAGS = -std=c++0x CFLAGS = -pg -D_DEBUG -g -c -Wall LFLAGS = -O LFLAGS = -pg -g
What am I missing?
Edit:I changed it to the following, but I still get compile errors, which I don't get with command line gcc invocation.
CXXFLAGS=-O3 -std=c++0x -pg -D_DEBUG -g -c -Wall
解决方案This way your makefile will use all of your
CFLAGS
:CFLAGS=-O3 -std=c++0x -pg -D_DEBUG -g -c -Wall
You're overriding them with each "CFLAGS=..." declaration.
Moreover, it should be
CXXFLAGS
, notCFLAGS
.CFLAGS
is for C applications.As @Florian Sowade said, you could use
CFLAGS += -O3 -std....
(or CXXFLAGS..), so that users can provide their own flags when executing make.这篇关于Makefile修改支持c ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!