这个问题在这里已经有了答案:
How does "make" app know default target to build if no target is specified?
(4 个回答)
2年前关闭。
我正在尝试编译各种静态库:
foo.c
foo.h
我的makefile看起来像:
foo.o: foo.c
cc -c foo.c
libfoo.a: foo.o
ar -rv libfoo.a foo.o
我只是调用
make
从目录。它编译 .c 文件并提供 .o 文件,但是,我没有得到 .a 文件。虽然,我可以按顺序运行确切的命令并获取 .a 文件。
我确定这很简单,我搞砸了。我已经查看了所有内容,但这些示例并没有真正帮助,因为它们比我的情况要复杂得多。
最佳答案
只需调用make
没有参数将默认使用第一个目标,即 foo.o
.由于这不依赖于 libfoo.a(当然为什么要这样做),所以永远不会触发第二个配方。
结果是 .o 文件,但没有 .a 文件。
来自 https://www.gnu.org/software/make/manual/html_node/Goals.html
By default, the goal is the first target in the makefile
如果由于任何原因你被迫使用 make 只是
make
,然后重新排序你的makefile中的部分,以确保第一个目标是你需要的。或者,如同一页几行后所述
You can manage the selection of the default goal from within your makefile using the .DEFAULT_GOAL variable (see Other Special Variables).
关于c++ - 未从编译静态库 C++(Linux 内核)中获取 .a 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60592205/