Makefile 初学者帮助
我正在尝试学习Makefile。我已经完成了一些可行的小项目,但现在我正在扩展它,但没有运气。这是问题所在。我试图编译子目录中的所有文件,然后将它们存储在 build/objects 目录中(我无法工作)并将二进制文件链接到 build/objects 目录中的文件。这是我到目前为止得到的:
#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
#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
它给了我错误:
make: *** No rule to make target `Graphics3D/*.o', needed by `game.bin'. Stop.
我不知道我做错了什么。提前致谢, 加西姆
I am trying to learn Makefiles. 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. 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) lt; -o $@
.PHONY: clean
clean:
-rm $(OUTPUT) $(OBJECTS)
Modules.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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在形成先决条件时使用通配符是错误的。
看一下 GNU make 手册的这一部分:
http://www.gnu.org/software/make/manual /make.html#通配符陷阱
Your use of wildcards in forming prerequisites is wrong.
Have a look at this section of the GNU make manual:
http://www.gnu.org/software/make/manual/make.html#Wildcard-Pitfall
修复方法非常简单:
The fix is pretty simple: