使目标无法匹配

时间:2016-12-17 20:36:00

标签: c++ makefile gnu-make

我正在研究我的第一个makefile,到目前为止已经做了很多。

BUILD = build
BIN = bin
OUTPUTNAME = game.out
INCLUDE = /internalLibraries/include

SRCFILES := $(wildcard src/*.cpp) 
OBJFILES := $(patsubst %.cpp,%.o,$(SRCFILES))
OBJFILES := $(foreach dir,$(OBJFILES),$(subst src/,,$(dir)))
DIR := $(dir $(OBJFILES))

$(foreach d,$(DIR),$(shell mkdir -p $(BUILD)/$(d)))
$(shell mkdir -p $(BIN))

CC = g++ 
CFLAGS  = -g -std=c++11
LIBS=-lsfml-graphics -lsfml-window -lsfml-system


G++_VER_LT48 := $(shell expr `$(CC) -dumpversion | cut -f1-2 -d.` \< 4.8 )
ifeq ("$(G++_VER_LT48)","1")
$(error old version of g++ not supported, upgrade to 4.8 or higher)
endif


default: $(BIN)/$(OUTPUTNAME)

$(info $(OBJFILES))
$(BIN)/$(OUTPUTNAME): $(BUILD)/$(OBJFILES)
    $(CC) $(CFLAGS) -o $(BIN)/$(OUTPUTNAME) $(BUILD)/main.o $(BUILD)/game.o $(BUILD)/food.o $(BUILD)/snake.o $(LIBS)


$(BUILD)/%.o: %.cpp
    $(CC) -c $(CFLAGS) $< -o $@ -I $(INCLUDE)

问题是,运行它会产生输出:

sidhin@DRAGONHEART:/mnt/c/Users/sidhi/Desktop/Projects/sfml-snake$ make
food.o game.o main.o snake.o
make: *** No rule to make target `build/food.o', needed by `bin/game.out'.  Stop.

问题是什么,我无法解决。

1 个答案:

答案 0 :(得分:1)

$(BUILD)/%.o: %.cpp

BUILD设置为&#34; build&#34;,这将指定用于构建名为&#34; build / food.o&#34;的目标的规则。来自&#34; food.cpp&#34;。

问题显然是&#34; food.cpp&#34;不存在。实际的源文件是&#34; src / food.cpp&#34;,基于您的声明:

SRCFILES := $(wildcard src/*.cpp)