【问题标题】:Makefile beginner helpMakefile 初学者帮助
【发布时间】:2011-07-05 09:12:58
【问题描述】:

我正在尝试学习 Makefile。我做了一些可行的小项目,但现在我正在扩展它,但没有运气。这是问题。我正在尝试从 subdirs 编译所有文件,然后将它们存储在 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)

模块.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.

我不知道我做错了什么。提前致谢, 加西姆

【问题讨论】:

    标签: compiler-construction makefile g++ setup-project gnu


    【解决方案1】:

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

    查看 GNU make 手册的这一部分:
    http://www.gnu.org/software/make/manual/make.html#Wildcard-Pitfall

    【讨论】:

      【解决方案2】:

      修复很简单:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-01-10
        • 1970-01-01
        • 2021-04-11
        • 2022-01-17
        • 1970-01-01
        • 1970-01-01
        • 2017-09-25
        • 2012-03-14
        相关资源
        最近更新 更多