我习惯在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 \ ^这是我的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我的错误在哪里? 为什么使用g++而不是clang ? 为什么不使用-std=c++11参数? 对不起初学者的问题,遗憾的是我无法找到谷歌的解决方案。
I'm used to program in IDEs, but switched to vim and plugins recently. Now I try to write a makefile for a c++ project, but somehow if I run make I always get the error
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:
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 doneWhere is my error? Why is it using g++ instead of clang? And why isn't it using the -std=c++11 parameter? Sorry for the beginner questions, I unfortunately can't find a solution with google.
最满意答案
make试图制作目标'* .o'。
因此,您可以明确指定源列表:
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注意变量OBJS和OBJS定义。
make tried to make target '*.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 doneNote definition of variables OBJS and SRCS.
更多推荐
发布评论