如何在makefile中设置编译标志?(how do I set compilingflags in a makefile?)

编程入门 行业动态 更新时间:2024-10-27 00:34:46
如何在makefile中设置编译标志?(how do I set compilingflags in a makefile?)

我习惯在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 done

Where 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 done

Note definition of variables OBJS and SRCS.

更多推荐

本文发布于:2023-07-16 15:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标志   如何在   compilingflags   makefile   set

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!