252

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)

ljbade
  • 4,576
  • 4
  • 30
  • 35
  • a similar question: [How do i find out what all symbols are exported from a shared object?](http://stackoverflow.com/questions/1237575/how-do-i-find-out-what-all-symbols-are-exported-from-a-shared-object) – Ilia K. Jan 31 '13 at 22:14

5 Answers5

398

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.

thkala
  • 84,049
  • 23
  • 157
  • 201
69

objdump -T *.so may also do the job

Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
user2391685
  • 1,006
  • 12
  • 16
15

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)
Martin Flaska
  • 673
  • 7
  • 10
7

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

frogatto
  • 28,539
  • 11
  • 83
  • 129
Vincent Fenet
  • 383
  • 2
  • 6
3

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

user941581
  • 389
  • 2
  • 4