c++ - 未从编译静态库 C++(Linux 内核)中获取 .a 文件

标签 c++ linux makefile static

这个问题在这里已经有了答案:





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/

相关文章:

c++ - 类具有虚函数和可访问的非虚析构函数

c++ - 异常:循环中内存位置的 std::bad_alloc

unix - 特殊 make 目标的依赖项 .DEFAULT 未触发

linux - CPU 时间更改后 GLUT 不更新

gcc - Makefile 想自己编译

c++ - Clrdump (C++) 错误 LNK2019 : unresolved external symbol __imp__RegisterFilter@8 referenced in function _main

c++ - 将字符串读入数组

c++ - 在Rcpp中的字符串类型之间转换时出错

linux - 显示已用磁盘空间,包括 bash 中的保留磁盘空间

python - 使用 cron 追加现有的 sqlite3 数据库