c++ - 我如何查看 Linux .so 或 .a 对象并查看它们包含哪些函数?

标签 c++ c unix static-libraries

链接器大概可以做到这一点,那么是否有一个命令行工具可以列出目标文件中的函数并告诉我函数的名称及其签名?

最佳答案

对于共享库,您必须使用:

nm -D /path/to/libwhatever.so.<num>

没有 -Dnm 转储 debug 符号; -D 指的是实际用于动态链接的动态符号。来自 Ubuntu 12 session :

$ nm /lib/i386-linux-gnu/libc.so.6 
nm: /lib/i386-linux-gnu/libc.so.6: no symbols
$ nm -D /lib/i386-linux-gnu/libc.so.6 | tail
0011fc20 T xdr_wrapstring
001202c0 T xdrmem_create
00115540 T xdrrec_create
001157f0 T xdrrec_endofrecord
00115740 T xdrrec_eof
00115690 T xdrrec_skiprecord
00120980 T xdrstdio_create
00120c70 T xencrypt
0011d330 T xprt_register
0011d450 T xprt_unregister

在这个系统上,libc.so 没有调试符号,所以 nm 什么也没有显示;当然,nm -D 揭示了动态链接机制的符号。

对于 .a 存档或 .o 目标文件,只需 nm。符号就是符号;如果这些文件被剥离,则这些对象不能用于链接。

this similar question 所述:

Exported sumbols are indicated by a T. Required symbols that must be loaded from other shared objects have a U. Note that the symbol table does not include just functions, but exported variables as well.

Or if you only want to see exported symbols, add the --defined-only flag. eg: nm -D --defined-only /lib/libtest.so

关于c++ - 我如何查看 Linux .so 或 .a 对象并查看它们包含哪些函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38887351/

相关文章:

c++ - g++如何在忽略函数返回值时获得警告

c++ - 使用 Petsc 库用 vector 构造稀疏矩阵

c - 在C中向数组添加值不起作用

Python 代码无法在浏览器上运行

python - 是否有 unix "file"实用程序的 python 等效项?

c++ - Qt Creator中如何使用QPainter显示动态圆圈

C++ 强制编译时错误/警告开关中的隐式失败

C++ thread assignment throwing SIGSEGV 收藏

c - 无法将 GDB 附加到 Eclipse CDT 中的进程

linux - sed 拆分单行文件并处理结果行