[英]Makefile for a C++ SDL project
I'm still learning how to set up a Makefile
and I'm kind of lost here.我仍在学习如何设置
Makefile
,我有点迷失在这里。 I'm using windows and currently trying to fire up my Makefile
for small C++ SDL project.我正在使用 Windows,目前正在尝试为小型 C++ SDL 项目启动我的
Makefile
。
I have 3 .cpp files:我有 3 个 .cpp 文件:
main.cpp
window.cpp
rect.cpp
As well as 2 extra header files:以及 2 个额外的头文件:
Window.h
rect.h
So having trouble setting up everything on a Makefile
This is what i currently have:所以无法在
Makefile
上设置所有内容这就是我目前拥有的:
CXXFLAGS = -Ideps/include -std=c++0x
LXXFLAGS = -Ldeps/lib -lmingw32 -lSDL2main -lSDL2
cup: main.o
g++ main.o -o cup $(LXXFLAGS)
main.o: main.cpp
g++ main.cpp -c $(CXXFLAGS)
window.o: window.cpp
g++ window.cpp -c
rect.o: rect.cpp
g++ rect.cpp -c
But I'm getting a bunch of undefined reference errors for my constructors on my command prompt.但是在我的命令提示符下,我的构造函数出现了一堆未定义的引用错误。 Help please!
请帮忙!
From the Makefile contents I read that cup
binary is only created from main.o
and it does not link window.o
nor rect.o
, which is where probably those missing references are defined.从 Makefile 内容中,我读到
cup
二进制文件仅从main.o
创建,它不链接window.o
或rect.o
,这可能是定义了那些缺失引用的地方。 At the very least I would update the primary rule to say:至少我会更新主要规则说:
cup: main.o window.o rect.o
g++ $(LXXFLAGS) -o cup $^
Thus said, you could make even more use from implicit rules that are built into make
, and, if following the standard naming for linking flags, the Makefile
could be reduced even further to just a linking line (as compilation rules are implicit), eg:因此,您可以更多地使用内置于
make
隐式规则,并且,如果遵循链接标志的标准命名,则Makefile
可以进一步减少到仅链接行(因为编译规则是隐式的),例如:
$ cat Makefile
CXXFLAGS = -Ideps/include -std=c++0x
LDFLAGS = -Ldeps/lib
LDLIBS = -lmingw32 -lSDL2main -lSDL2
cup: main.o window.o rect.o
$(LINK.cc) $^ $(LDLIBS) -o $@
Output:输出:
$ make
g++ -Ideps/include -std=c++0x -c -o main.o main.cpp
g++ -Ideps/include -std=c++0x -c -o window.o window.cpp
g++ -Ideps/include -std=c++0x -c -o rect.o rect.cpp
g++ -Ideps/include -std=c++0x -Ldeps/lib main.o window.o rect.o -lmingw32 -lSDL2main -lSDL2 -o cup
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.