链接器大概可以做到这一点,那么是否有一个命令行工具可以列出目标文件中的函数并告诉我函数的名称及其签名?
最佳答案
对于共享库,您必须使用:
nm -D /path/to/libwhatever.so.<num>
没有 -D
,nm
转储 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 aU
. 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/