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

LinuxExportShared Libraries

Linux Problem Overview


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

What command allows me to do this?

(On Windows I use the program depends)

Linux Solutions


Solution 1 - Linux

What you need is nm and its -D option:

$ 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.

See the nm manual page for more information.

Solution 2 - Linux

objdump -T *.so may also do the job

Solution 3 - Linux

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

Solution 4 - Linux

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

$ 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)

Solution 5 - Linux

Just in case some Mac user is looking here, use llvm-cxxdump or llvm-readelf -sW

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionljbadeView Question on Stackoverflow
Solution 1 - LinuxthkalaView Answer on Stackoverflow
Solution 2 - Linuxuser2391685View Answer on Stackoverflow
Solution 3 - LinuxVincent FenetView Answer on Stackoverflow
Solution 4 - LinuxMartin FlaskaView Answer on Stackoverflow
Solution 5 - Linuxuser941581View Answer on Stackoverflow