[英]How do I make my Makefile use my CFLAGS flags when automatically compiling object files?
I have a Makefile for this game I'm making. 我正在为此游戏制作一个Makefile。 It looks like this.
看起来像这样。
CC = g++
CFLAGS = -std=c++11 -w
game: main.o item.o game.o player.o map.o room.o menu.o notebook.o enemy.o
$(CC) $(CFLAGS) -o game main.o item.o game.o player.o map.o room.o menu.o notebook.o enemy.o
mv game ../
I am using the -std=c++11
line in the CFLAGS
line, however, when I run make
, I am told that I need to use C++11 since I am using the #include <random>
line in one of my files. 我在
CFLAGS
行中使用-std=c++11
行,但是,当我运行make
,被告知我需要使用C ++ 11,因为我在其中之一中使用#include <random>
行我的文件。 I hadn't noticed the compilation wasn't always using the CFLAGS line when compiling until this. 我一直没注意到编译在编译之前并不总是使用CFLAGS行。
What do I need to do in order to make the automatic compilation of the object files use the CFLAGS
also? 为了使目标文件的自动编译也使用
CFLAGS
我需要做什么?
Specify how to generate your .o files: 指定如何生成您的.o文件:
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
As @juanchopanza mentions, you should really be using CXX
and CXXFLAGS
. 正如@juanchopanza所提到的,您确实应该使用
CXX
和CXXFLAGS
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.