简体   繁体   English

Makefile 初学者帮助

[英]Makefile beginner help

I am trying to learn Makefiles.我正在尝试学习 Makefile。 I have done some small project that works but now im extending it but getting no luck.我做了一些可行的小项目,但现在我正在扩展它,但没有运气。 Here is the question.这是问题。 I am trying to compile all the files from subdirs and then store them in build/objects directory (which i cannot get to work) and link the binary to the files in the build/objects directory.我正在尝试从 subdirs 编译所有文件,然后将它们存储在 build/objects 目录中(我无法开始工作)并将二进制文件链接到 build/objects 目录中的文件。 Here is what i have gotten so far:这是我到目前为止所得到的:

#compiler vars
CC=g++
CFLAGS=-c -Wall
LDFLAGS= 


#build vars
INCLUDE=-I. -IFramework/ -IGame/
SOURCES=test.cpp

include Modules.mk
ifeq ($(mod3D), true)
SOURCES += $(mod3D_src)
INCLUDE += $(mod3D_include)
endif

ifeq ($(mod2D), true)
SOURCES += $(mod2D_src)
INCLUDE += $(mod2D_include)
endif

ifeq ($(modInput), true)
SOURCES += $(modInput_src)
INCLUDE += $(modInput_include)
endif

OBJECTS=$(SOURCES:.cpp=.o)
OUTPUT=game.bin

all: $(SOURCES) $(OUTPUT)

$(OUTPUT): $(OBJECTS)
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o: $(SOURCES)
    $(CC) $(CFLAGS) $(INCLUDE) $< -o $@

.PHONY: clean

clean:
    -rm $(OUTPUT) $(OBJECTS)

Modules.mk模块.mk

#Modules
mod3D=true
mod2D=true
modInput=true

mod3D_include=-IGraphics3D
mod2D_include=-IGraphics2D
modInput_include=-IInput

mod3D_src=Graphics3D/*.cpp
mod2D_src=#Graphics2D/*.cpp
modInput_src=Input/*.cpp

it gives me error:它给了我错误:

make: *** No rule to make target `Graphics3D/*.o', needed by `game.bin'.  Stop.

I don't know what am I doing wrong.我不知道我做错了什么。 Thanks in advance, Gasim提前致谢, 加西姆

Your use of wildcards in forming prerequisites is wrong.您在形成先决条件时使用通配符是错误的。

Have a look at this section of the GNU make manual:查看 GNU make 手册的这一部分:
http://www.gnu.org/software/make/manual/make.html#Wildcard-Pitfall http://www.gnu.org/software/make/manual/make.html#Wildcard-Pitfall

The fix is pretty simple:修复非常简单:

mod3D_src = $(wildcard Graphics3D/*.cpp)
# and likewise:
mod2D_src = # $(wildcard Graphics2D/*.cpp)
modInput_src = $(wildcard Input/*.cpp)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM