繁体   English   中英

检查静态库中定义的所有符号

[英]Check that all symbols defined in static library

我构建了一些没有错误的静态库。
当我尝试将它链接到某个应用程序时,我意识到库中的某些符号未定义。

我想在库构建步骤而不是应用程序上出错。

换句话说

$ cat mylib.h
void foo();
$ cat mylib.c
#include "mylib.h"
// no foo() implementation here;
$ cat test.c 
#include "mylib.h"

int main() {
    foo();
    return 0;
}
$ gcc mylib.c -c
$ ar crf libmylib.a *.o
$ gcc test.c -lmylib -L.
/tmp/cc7201uP.o: In function `main':
test.c:(.text+0xa): undefined reference to `foo'
collect2: error: ld returned 1 exit status

我想在其中一个步骤中出错

$ gcc mylib.c -c
$ ar crf libmylib.a *.o

有没有可能,对于这种情况有什么好的做法?

更新:我试过$ nm --undefined-only *.a输出是:

mylib.o:

对我来说有点奇怪。 我希望在输出中包含foo()类的东西。

静态库只是一堆.o文件,这些文件应该具有未定义的引用。 .o文件生成.a时不涉及链接。

您可以运行nm --undefined-only libmylib.a并生成所有未定义符号的列表。 该列表将包括您在 C 标准库中使用的所有符号,因为同样在生成.a文件时不涉及链接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM