[英]how do I set compilingflags in a makefile?
I'm used to program in IDEs, but switched to vim and plugins recently. 我曾经在IDE中编程,但是最近切换到了vim和插件。 Now I try to write a makefile for a c++ project, but somehow if I run make
I always get the error 现在,我尝试为C ++项目编写一个makefile,但是如果我运行make
我总是会收到错误消息
g++ -c -o *.o createOutput.cpp
In file included from /usr/include/c++/4.8/thread:35:0,
from createOutput.cpp:5:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
^
This is my makefile: 这是我的makefile:
CC = clang++
# compiler flags
CFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system
all: program.exe clean
program.exe: *.o
$(CC) -o program.exe *.o $(CFLAGS) $(CFLAGS_SFML)
getInput.o: getInput.cpp
$(CC) -c getInput.cpp $(CFLAGS)
createOutput.o: createOutput.cpp
$(CC) -c createOutput.cpp $(CFLAGS)
main.o: main.cpp
$(CC) -c main.cpp $(CFLAGS)
.PHONY: clean
clean:
rm *.o
@echo clean done
Where is my error? 我的错误在哪里? Why is it using g++
instead of clang
? 为什么使用g++
而不是clang
? And why isn't it using the -std=c++11
parameter? 为什么不使用-std=c++11
参数呢? Sorry for the beginner questions, I unfortunately can't find a solution with google. 抱歉,对于初学者的问题,很遗憾,我找不到google解决方案。
您想要设置CXXFLAGS
,它会由make
自动拾取(并发送到编译器( 例如 g++
, clang++
等 ))。
make
tried to make target '*.o'. make
试图使目标“*的.o”。
So, instead of that, you can specify sources list explicitly: 因此,相反,您可以显式指定源列表:
CC = clang++
#compiler flags
CFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system
SRCS = getInput.cpp createOutput.cpp main.cpp
OBJS = $(SRCS:.cpp=.o)
all: program.exe
program.exe: $(OBJS)
$(CC) -o program.exe *.o $(CFLAGS) $(CFLAGS_SFML)
getInput.o: getInput.cpp
$(CC) -c getInput.cpp $(CFLAGS)
createOutput.o: createOutput.cpp
$(CC) -c createOutput.cpp $(CFLAGS)
main.o: main.cpp
$(CC) -c main.cpp $(CFLAGS)
.PHONY : clean
clean:
rm *.o
@echo clean done
Note definition of variables OBJS
and SRCS
. 注意变量的定义OBJS
和SRCS
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.