多文件Makefile编译
Multiple files Makefile compilation
如何在一个makefile中编译2个.cpp文件和1个.h文件?
我是 makefile 的新手,但我不想一直在命令行中执行此操作(因为我需要添加库和链接器选项等,但我知道该怎么做)。
我已经做了很多研究,包括手册,但我还是不明白。
这是我写的 makefile:
HEADERS = program.h headers.h
default: program
program.o: program.cpp $(HEADERS)
g++ -c program.cpp -o program.o
program: program.o
g++ program.o -o program
clean:
-rm -f program.o
-rm -f program
我的 makefile 用于 1 个文件。如何为 3 个文件(2 个 .cpp、1 个 .h)执行此操作?
非常感谢任何帮助。
感谢anatolyg
的解释:
You don't need to "compile" h-files Maybe this was the bit that made it all so difficult for you. You only need to compile the cpp files. Header files are included in the makefile just for make to figure out when to recompile the source files.
多亏了这个,我发现我只需要制作一个 makefile 来编译 2 个 .cpp 文件,它会处理其余的。
非常感谢anatolyg
。谢谢:)
如何在一个makefile中编译2个.cpp文件和1个.h文件? 我是 makefile 的新手,但我不想一直在命令行中执行此操作(因为我需要添加库和链接器选项等,但我知道该怎么做)。
我已经做了很多研究,包括手册,但我还是不明白。
这是我写的 makefile:
HEADERS = program.h headers.h
default: program
program.o: program.cpp $(HEADERS)
g++ -c program.cpp -o program.o
program: program.o
g++ program.o -o program
clean:
-rm -f program.o
-rm -f program
我的 makefile 用于 1 个文件。如何为 3 个文件(2 个 .cpp、1 个 .h)执行此操作?
非常感谢任何帮助。
感谢anatolyg
的解释:
You don't need to "compile" h-files Maybe this was the bit that made it all so difficult for you. You only need to compile the cpp files. Header files are included in the makefile just for make to figure out when to recompile the source files.
多亏了这个,我发现我只需要制作一个 makefile 来编译 2 个 .cpp 文件,它会处理其余的。
非常感谢anatolyg
。谢谢:)