【发布时间】:2021-08-14 22:25:07
【问题描述】:
我想生成依赖于目标文件 (OBJS = $(wildcard $(BUILD_DIR)/*.o) 的可执行文件 (TARGET = $(BUILD_DIR)/MySDLProgram),这些目标文件依赖于位于 src/application 和 src/engine 中的源文件。我应该如何进行?
我不断收到此错误:
Note that Makefile not found the object files
这是我的 Makefile:
#CC specifies which compiler we're using
CC = g++
# Directories
SRC_DIR = src
BUILD_DIR = build
TARGET = $(BUILD_DIR)/MySDLProgram
# Source files
SRC_DIRS = src/engine src/application
SRCS = $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)/*.cpp))
OBJS = $(wildcard $(BUILD_DIR)/*.o)
# INCLUDE_PATHS specifies the additional include paths we'll need
INCLUDE_PATHS = -Iheader
# COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
# -Wl,-subsystem,windows gets rid of the console window
# COMPILER_FLAGS = -w -Wl,-subsystem,windows
COMPILER_FLAGS = -g -O0 -Wall -std=c++11
#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lSDL2
.PHONY: all
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(INCLUDE_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) $^ -o $@
$(BUILD_DIR)/%.o: $(foreach dir, $(SRC_DIRS), $(dir))/%.cpp | $(BUILD_DIR)
$(CC) $(INCLUDE_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) $< -o $@
$(BUILD_DIR):
mkdir -p $@
exec: $(BIN)
$(BIN).exe
clean:
@$(RM) -rv $(BUILD_DIR)/*
这些是我要运行的命令:
$ g++ -Iheader -g -O0 -Wall -std=c++11 -lmingw32 -lSDL2main -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lSDL2 src/engine/Game.cpp -c -o build/Game.o
$ g++ -Iheader -g -O0 -Wall -std=c++11 -lmingw32 -lSDL2main -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lSDL2 src/engine/Music.cpp -c -o build/Music.o
$ g++ -Iheader -g -O0 -Wall -std=c++11 -lmingw32 -lSDL2main -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lSDL2 src/engine/State.cpp -c -o build/State.o
$ g++ -Iheader -g -O0 -Wall -std=c++11 -lmingw32 -lSDL2main -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lSDL2 src/engine/Sprite.cpp -c -o build/Sprite.o
$ g++ -Iheader -g -O0 -Wall -std=c++11 -lmingw32 -lSDL2main -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lSDL2 src/application/Main.cpp -c -o build/Main.o
$ g++ -g -O0 -Wall -std=c++11 -lmingw32 -lSDL2main -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lSDL2 build/Main.o build/Game.o build/Music.o build/Sprite.o build/State.o
我使用的是 MSYS2 环境。
【问题讨论】: