- publishing free software manuals
An Introduction to GCC - for the GNU compilers gcc and g++
by Brian J. Gough, foreword by Richard M. Stallman
Paperback (6"x9"), 144 pages
ISBN 0954161793
RRP £12.95 ($19.95)

"Answers common questions and provides many useful hints" --- Dr. Gerald Pfeifer (SUSE) -- Technical Editor Get a printed copy>>>

12.3 Finding dynamically linked libraries

When a program has been compiled using shared libraries it needs to load those libraries dynamically at run-time in order to call external functions. The command ldd examines an executable and displays a list of the shared libraries that it needs. These libraries are referred to as the shared library dependencies of the executable.

For example, the following commands demonstrate how to find the shared library dependencies of the Hello World program:

$ gcc -Wall hello.c
$ ldd a.out 
libc.so.6 => /lib/libc.so.6 (0x40020000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

The output shows that the Hello World program depends on the C library libc (shared library version 6) and the dynamic loader library ld-linux (shared library version 2).

If the program uses external libraries, such as the math library, these are also displayed. For example, the calc program (which uses the sqrt function) generates the following output:

$ gcc -Wall calc.c -lm -o calc
$ ldd calc
libm.so.6 => /lib/libm.so.6 (0x40020000)
libc.so.6 => /lib/libc.so.6 (0x40041000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

The first line shows that this program depends on the math library libm (shared library version 6), in addition to the C library and dynamic loader library.

The ldd command can also be used to examine shared libraries themselves, in order to follow a chain of shared library dependencies.

ISBN 0954161793An Introduction to GCC - for the GNU compilers gcc and g++See the print edition