gpt4 book ai didi

c++ - Make 无法匹配目标

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:11:13 28 4
gpt4 key购买 nike

我正在编写我的第一个 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.

什么问题,我搞不明白。

最佳答案

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

BUILD 设置为“build”,这指定了从“food.cpp”构建名为“build/food.o”的目标的规则。

问题显然是“food.cpp”不存在。根据您的声明,实际的源文件是“src/food.cpp”:

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

关于c++ - Make 无法匹配目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41202796/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com