kar*_*kkk 1 c++ makefile gnu-make
我正在开发一个 SDL 项目,我使用 makefile 来构建它。我正在使用 MinGW w64 编译器和 make 在 Windows 上执行此操作。
我的项目结构看起来像这样
proj
------>bin #stores the executable
------>include #stroes the external library include files
------>lib #stores the lib files of the libraries
------>obj #stores the .o files
------>src #source files
makefile
Run Code Online (Sandbox Code Playgroud)
我的 makefile 看起来像这样
CC = g++
OUT = main
ODIR = ./obj
SDIR = ./src
OUTDIR = ./bin
IDIR = ./include
LDIR = ./lib
libs = -lmingw32 -lSDL2main -lSDL2
OBJS = $(patsubst $(SDIR)/%.cpp,$(ODIR)/%.o,$(wildcard $(SDIR)/*.cpp))
$(ODIR)/%.o : $(SDIR)/%.cpp
$(CC) -c -I $(IDIR) -o $@ $^
$(OUTDIR)/% : $(OBJS)
$(CC) -L $(LDIR) -o $@ $^ $(libs)
.PHONY : run
run :
$(OUTDIR)/$(OUT)
Run Code Online (Sandbox Code Playgroud)
最初,makefile 工作得很好,在我通过编辑 src 变量编辑 makefile 然后取消它后,make 文件给出了错误
make ./obj/main.o
make: *** No rule to make target `obj/main.o'. Stop.
Run Code Online (Sandbox Code Playgroud)
我尝试将文件重命名为 MakeFile 或 a.mk 并尝试运行它,但即使这样也无济于事。
那么我应该做什么才能让它发挥作用呢?