How to list shared library dependencies used by an application

June 15th, 2008 mysurface Posted in Developer, ldd | Hits: 172754 | 9 Comments »

Almost every application in Linux uses shared library, even the one compiled by yourself with gcc. You may have realized that application compiled with gcc 4.1 in Fedora or Ubuntu does not able to run under Red Hat ES3 or ES4. Or some other new applications does not able to run at legacy Linux, it is all because of missing shared library dependencies.

Is there any work around solution to allow legacy Linux uses new version of application?
My guess is as long as we resolved those dependencies completely, the application should works under any linux platform, unless the application or its dependencies required kernel version are not match.

Is there any ways to know what shared library are used by a specific application?
We can use ldd. Lets take a simple application for example. I have wrote a fun app uses ncurses library, its call “matrix”. It does nothing but simulate the running characters flow from top to bottom in the movie matrix at your linux console. You may get the source code as well as the binaries at HERE.

ldd matrix

        linux-gate.so.1 =>  (0x00110000)
        libncurses.so.5 => /lib/libncurses.so.5 (0x00111000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x0793a000)
        libm.so.6 => /lib/libm.so.6 (0x0056e000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x0790d000)
        libc.so.6 => /lib/libc.so.6 (0x00413000)
        libdl.so.2 => /lib/libdl.so.2 (0x00599000)
        libtinfo.so.5 => /lib/libtinfo.so.5 (0x00ad0000)
        /lib/ld-linux.so.2 (0x003f4000)

Observed that, it uses libncurses.so.5. You may find this file in /usr/lib, /usr/share/lib or /lib. Bear in mind, libncurses.so.5 probably is just a symbolic link, you need to copy the real .so instead of its symlink.

The shared library itself sometimes also have dependencies too, which it may also use some other shared library, to fully resolved that, we can add verbose to ldd for more details.

ldd -v matrix

...
        /lib/libncurses.so.5:
                libdl.so.2 (GLIBC_2.1) => /lib/libdl.so.2
                libdl.so.2 (GLIBC_2.0) => /lib/libdl.so.2
                libc.so.6 (GLIBC_2.1.3) => /lib/libc.so.6
                libc.so.6 (GLIBC_2.4) => /lib/libc.so.6
                libc.so.6 (GLIBC_2.3) => /lib/libc.so.6
                libc.so.6 (GLIBC_2.1) => /lib/libc.so.6
                libc.so.6 (GLIBC_2.3.4) => /lib/libc.so.6
                libc.so.6 (GLIBC_2.0) => /lib/libc.so.6
...

It seems my ncurses lib uses libdl and glibc.

9 Responses to “How to list shared library dependencies used by an application”

  1. Nice post.
    Could you explain more about the version of GLIBC? why same shared library depends on multiple different version GLIBC?

    Thanks

  2. You failed to mentioned that one must change directory to the location of a program in question. For example,

    ~$ cd /usr/bin
    /usr/bin$ ldd -v nano

  3. Or provide a full path, i.e.

    ~$ ldd -v /usr/bin/nano

  4. @James: GLIBC has to be backward compatible, it includes object symbols of various version.

    @Al: You may want to use which,
    ldd -v `which nano`

  5. which command will list share libraries used by KDE application kpand

  6. @matthew
    ldd `which kpand`

  7. From just under the ‘ldd matrix’ code block:

    “Bare in mind,..” ??

    You asked us to get our minds naked, dude.

    The verb bare means “to expose, to uncover,” as in ‘She accidentally bared her breasts at the pool’.

    The verb bear means “to carry, to bring forth, to take along,” and the like, as in ‘Bear with me’.

    The noun bear is the animal.

    A common error in an otherwise excellent writeup; see “duel v. dual” for more hilarity.

  8. Omg, haha. It is a typo, I corrected. Thanks Elisa, and please bear with me :)

  9. hi! One problem is when one crucial library is missing, then ldd only says: No such file or directory, but NOT which library that is missing.

Leave a Reply