简体   繁体   English

自动编译目标文件时,如何使我的Makefile使用CFLAGS标志?

[英]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所提到的,您确实应该使用CXXCXXFLAGS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过修改make命令覆盖我的Makefile中的标志 - How can I override flags in my Makefile by modifying the make command 如何让我的 makefile 创建第二个可执行文件? - How do I make my makefile create a second executable? 困惑我的Makefile如何重新生成目标文件 - Confused how my Makefile is remaking object files 我可以让我的Makefile自动让GCC使用它支持的最新标准吗? - Can I have my Makefile automatically make GCC use the most recent standard it supports? C ++:Makefile:目标文件无法编译? 然后说没有找到对象 - C++: Makefile: object files not compiling? make then says objects not found C++ 如何使我的程序不会删除正在使用的文件? - C++ How do I make it so my program wouldn't delete files that are in use? 为什么我的 makefile 没有生成目标文件? - Why is my makefile not generating object files? 使用不同的标志重构对象文件的Makefile - Refactoring Makefile for object files with different flags 当我使用 WNetAddConnection2 或 WNetAddConnection3 时,如何让操作系统保存我的凭据? - How do I make the operating system save my credentials when I use WNetAddConnection2 or WNetAddConnection3? 编译我的 3 个文件时,我收到错误,提示“operator=”不匹配 - when compiling my 3 files I received errors saying no match for 'operator='
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM