Makefile 初学者帮助

发布于 2024-11-18 15:14:08 字数 1212 浏览 3 评论 0原文

我正在尝试学习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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鲸落 2024-11-25 15:14:08

您在形成先决条件时使用通配符是错误的。

看一下 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

冷月断魂刀 2024-11-25 15:14:08

修复方法非常简单:

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

The fix is pretty simple:

mod3D_src = $(wildcard Graphics3D/*.cpp)
# and likewise:
mod2D_src = # $(wildcard Graphics2D/*.cpp)
modInput_src = $(wildcard Input/*.cpp)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文