如何查看 Linux 共享库导出的函数列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4514745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:02:17  来源:igfitidea点击:

How do I view the list of functions a Linux shared library is exporting?

linuxexportshared-libraries

提问by ljbade

I want to view the exported functions of a shared library on Linux.

我想在Linux上查看一个共享库的导出函数。

What command allows me to do this?

什么命令允许我这样做?

(On Windows I use the program depends)

(在 Windows 上我使用的程序取决于)

采纳答案by thkala

What you need is nmand its -Doption:

您需要的是nm及其-D选项:

$ nm -D /usr/lib/libopenal.so.1
.
.
.
00012ea0 T alcSetThreadContext
000140f0 T alcSuspendContext
         U atanf
         U calloc
.
.
.

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.

导出的 sumbol 由T. 必须从其他共享对象加载的必需符号具有U. 请注意,符号表不仅包括函数,还包括导出的变量。

See the nmmanual pagefor more information.

有关更多信息,请参阅nm手册页

回答by user2391685

objdump -T *.somay also do the job

objdump -T *.so也可以做这份工作

回答by Vincent Fenet

On a MAC, you need to use nm *.o | c++filt, as there is no -Coption in nm.

在Mac上,你需要使用nm *.o | c++filt,因为没有-C在选项nm

回答by Martin Flaska

Among other already mentioned tools you can use also readelf(manual). It is similar to objdumpbut goes more into detail. See thisfor the difference explanation.

在其他已经提到的工具中,您也可以使用readelf手册)。它类似于objdump但更详细。有关差异说明,请参阅此内容

$ readelf -sW /lib/liblzma.so.5 |head -n10

Symbol table '.dynsym' contains 128 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 FUNC    GLOBAL DEFAULT  UND pthread_mutex_unlock@GLIBC_2.0 (4)
     2: 00000000     0 FUNC    GLOBAL DEFAULT  UND pthread_mutex_destroy@GLIBC_2.0 (4)
     3: 00000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTable
     4: 00000000     0 FUNC    GLOBAL DEFAULT  UND memmove@GLIBC_2.0 (5)
     5: 00000000     0 FUNC    GLOBAL DEFAULT  UND free@GLIBC_2.0 (5)
     6: 00000000     0 FUNC    GLOBAL DEFAULT  UND memcpy@GLIBC_2.0 (5)