我习惯在 IDE 中编程,但最近切换到 vim 和插件。现在我尝试为一个 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 \
^
这是我的生成文件:
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
我的错误在哪里?为什么使用 g++
而不是 clang
?为什么不使用 -std=c++11
参数?对于初学者的问题,很抱歉,很遗憾,我无法通过谷歌找到解决方案。
最佳答案
你想设置 CXXFLAGS
,它会被 make
自动获取(并发送给你的编译器(eg g++
、clang++
、等)。
关于c++ - 如何在 makefile 中设置编译标志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34535871/