233

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,366
  • 3
  • 29
  • 34
  • 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

377

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
  • 80,583
  • 22
  • 150
  • 196
63

objdump -T *.so may also do the job

Jeroen Vannevel
  • 42,521
  • 22
  • 100
  • 163
user2391685
  • 946
  • 10
  • 16
8

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

frogatto
  • 27,475
  • 10
  • 76
  • 119
Vincent Fenet
  • 386
  • 2
  • 6
6

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
  • 403
  • 4
  • 7
0

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

user941581
  • 329
  • 2
  • 4