我正在尝试为一个非常简单的程序练习使用Makefiles。程序文件为:
main.cpp
other.cpp
other.h
我希望最终的可执行文件是Prog。
运行此命令时会发生什么情况,我得到了main.o和other.o,但没有Prog。
我在这里想念什么?
## file Makefile
CXXOBJECTS= %.o
CXX= g++
CXXSOURCES= main.cpp other.cpp
CXXFLAGS= -std=c++11 -O2
Prog : main.o other.o
main.o : main.cpp
other.o : other.cpp other.h
## eof Makefile
最佳答案
你快到了。您具有以下内容:
Prog: main.o other.o ## these are your dependencies
g++ main.o other.o -o Prog
这应该给您一个名为
Prog
的可执行文件。虽然实际上,一个更好的makefile是这样的:CXXOBJECTS= %.o
CXX= g++
CXXSOURCES= main.cpp other.cpp
CXXFLAGS= -std=c++11 -O2
Prog: main.o other.o ## these are your dependencies
CXX main.o other.o -o Prog
main.o : main.cpp
CXX CXXFLAGS -c main.cpp
other.o : other.cpp
CXX CXXFLAGS -c other.cpp
实际上,您可以使其变得更好,但是我不记得我的头上有makefile的语法糖(IDE的:P)
关于c++ - 此makefile仅创建.o文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23155114/