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):
我可以使用gcc和-std=c++0x选项编译一个文件。但是我不能通过makefile来实现。这里是我的makefile中的一组标志(在对c++11关键字进行了抱怨之后):
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.
编辑:我将其更改为以下内容,但仍然会出现编译错误,我无法使用命令行gcc调用。
CXXFLAGS=-O3 -std=c++0x -pg -D_DEBUG -g -c -Wall
3 个解决方案
#1
12
This way your makefile will use all of your CFLAGS
:
这样,makefile将使用所有的CFLAGS:
CFLAGS=-O3 -std=c++0x -pg -D_DEBUG -g -c -Wall
You're overriding them with each "CFLAGS=..." declaration.
您用每个“CFLAGS=…”声明来覆盖它们。
Moreover, it should be CXXFLAGS
, not CFLAGS
. CFLAGS
is for C applications.
此外,它应该是CXXFLAGS,而不是CFLAGS。CFLAGS用于C应用程序。
As @Florian Sowade said, you could use CFLAGS += -O3 -std....
(or CXXFLAGS..), so that users can provide their own flags when executing make.
作为@Florian Sowade说,您可以使用CFLAGS + = o3化....(或CXXFLAGS.),以便用户在执行时可以提供自己的标志。
#2
3
You can keep it in multiple lines, but you probably want to append, not to assign:
您可以将它保持在多行中,但是您可能想要追加,而不是分配:
# e.g.
CFLAGS += -O3
CFLAGS += -std=c++0x
CFLAGS += -pg -D_DEBUG -g -c -Wall
#3
0
Where did you get that mess from? That makefile was wrong long before you modified it for C++11.
你从哪里弄来的?在修改c++ 11之前,这个makefile是错误的。
Let's start with the first line:
让我们从第一行开始:
MACHINE = $(shell echo `uname -s`-`uname -m` | sed "s/ //g")
Try running the command echo `uname -s`-`uname -m`
and you'll see if has no spaces in anyway, so what's the point in the sed
command?
试着运行这个命令echo ' uname -s ' - ' uname -m ',然后你会看到是否没有空格,那么sed命令的要点是什么?
Maybe you want this:
也许你想要这样的:
MACHINE = $(shell uname -s -m | sed "s/ /-/g")
That only runs two processes (uname and sed) not four (two unames, echo and sed)
它只运行两个进程(uname和sed)而不是四个进程(两个unames, echo和sed)
If you're using GNU make it should be
如果你使用GNU,那就应该是。
MACHINE := $(shell uname -s -m | sed "s/ /-/g")
So it's only run once.
所以它只运行一次。
CCC = CC
What is CC
?
CC是什么?
CCC = g++
Oh, it doesn't matter, you've replaced the value anyway. The conventional make variable for the C++ compiler is CXX
哦,没关系,反正你已经换掉了。c++编译器的常规make变量是CXX。
CFLAGS = -O3
CFLAGS = -std=c++0x
CFLAGS = -pg -D_DEBUG -g -c -Wall
As others have pointed out, you set CFLAGS, then set it to something different, then to something different. Only the last value will be kept.
正如其他人指出的那样,您设置了CFLAGS,然后将其设置为不同的东西,然后将其设置为不同的东西。只保留最后一个值。
LFLAGS = -O
LFLAGS = -pg -g
Same here, and what is LFLAGS
? Do you mean LDFLAGS
?
这里也一样,什么是LFLAGS?你是说LDFLAGS吗?
A good way to debug makefiles is to create a target to print out the variables you are setting, to check they have the values you expect:
调试makefile的一个好方法是创建一个目标来打印您正在设置的变量,检查它们是否有您期望的值:
print-vars:
echo CFLAGS is $(CFLAGS)
echo LDFLAGS is $(LDFLAGS)
#1
12
This way your makefile will use all of your CFLAGS
:
这样,makefile将使用所有的CFLAGS:
CFLAGS=-O3 -std=c++0x -pg -D_DEBUG -g -c -Wall
You're overriding them with each "CFLAGS=..." declaration.
您用每个“CFLAGS=…”声明来覆盖它们。
Moreover, it should be CXXFLAGS
, not CFLAGS
. CFLAGS
is for C applications.
此外,它应该是CXXFLAGS,而不是CFLAGS。CFLAGS用于C应用程序。
As @Florian Sowade said, you could use CFLAGS += -O3 -std....
(or CXXFLAGS..), so that users can provide their own flags when executing make.
作为@Florian Sowade说,您可以使用CFLAGS + = o3化....(或CXXFLAGS.),以便用户在执行时可以提供自己的标志。
#2
3
You can keep it in multiple lines, but you probably want to append, not to assign:
您可以将它保持在多行中,但是您可能想要追加,而不是分配:
# e.g.
CFLAGS += -O3
CFLAGS += -std=c++0x
CFLAGS += -pg -D_DEBUG -g -c -Wall
#3
0
Where did you get that mess from? That makefile was wrong long before you modified it for C++11.
你从哪里弄来的?在修改c++ 11之前,这个makefile是错误的。
Let's start with the first line:
让我们从第一行开始:
MACHINE = $(shell echo `uname -s`-`uname -m` | sed "s/ //g")
Try running the command echo `uname -s`-`uname -m`
and you'll see if has no spaces in anyway, so what's the point in the sed
command?
试着运行这个命令echo ' uname -s ' - ' uname -m ',然后你会看到是否没有空格,那么sed命令的要点是什么?
Maybe you want this:
也许你想要这样的:
MACHINE = $(shell uname -s -m | sed "s/ /-/g")
That only runs two processes (uname and sed) not four (two unames, echo and sed)
它只运行两个进程(uname和sed)而不是四个进程(两个unames, echo和sed)
If you're using GNU make it should be
如果你使用GNU,那就应该是。
MACHINE := $(shell uname -s -m | sed "s/ /-/g")
So it's only run once.
所以它只运行一次。
CCC = CC
What is CC
?
CC是什么?
CCC = g++
Oh, it doesn't matter, you've replaced the value anyway. The conventional make variable for the C++ compiler is CXX
哦,没关系,反正你已经换掉了。c++编译器的常规make变量是CXX。
CFLAGS = -O3
CFLAGS = -std=c++0x
CFLAGS = -pg -D_DEBUG -g -c -Wall
As others have pointed out, you set CFLAGS, then set it to something different, then to something different. Only the last value will be kept.
正如其他人指出的那样,您设置了CFLAGS,然后将其设置为不同的东西,然后将其设置为不同的东西。只保留最后一个值。
LFLAGS = -O
LFLAGS = -pg -g
Same here, and what is LFLAGS
? Do you mean LDFLAGS
?
这里也一样,什么是LFLAGS?你是说LDFLAGS吗?
A good way to debug makefiles is to create a target to print out the variables you are setting, to check they have the values you expect:
调试makefile的一个好方法是创建一个目标来打印您正在设置的变量,检查它们是否有您期望的值:
print-vars:
echo CFLAGS is $(CFLAGS)
echo LDFLAGS is $(LDFLAGS)