How to list exported functions in a shared lib on

2019-02-01 18:51发布

问题:

I have just built a shared lib on Ubuntu, and when I attempt to use the function, the application that loads the library is reporting 'xxx' symbol not found.

I want to check (i.e. list) the functions that are exported by my library so I can investigate this issue further.

Relevant details:

OS: Ubuntu 9.10 compiler: gcc 4.4.1 linker: GNU ld 2.20

回答1:

Try the nm utility.

GNU nm lists the symbols from object files objfile.... If no object files are listed as arguments, nm assumes the file a.out. [reference]



回答2:

nm -D -C -g <library>

works well too.



回答3:

Is your shared library in the library load path or in the application's run-time search path? It sounds like the dynamic linker can't find your library. Try running ldd on your application to see if the library can be found at run-time, e.g.:

$ ldd /usr/bin/less
    linux-gate.so.1 =>  (0x0072a000)
    libncurses.so.5 => /lib/libncurses.so.5 (0x00c68000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x007c7000)
    libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00286000)
    /lib/ld-linux.so.2 (0x002a1000)

See the ld.so(8) man page for additional details on library search paths.