Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

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.


 
 
  Published under the terms of the GNU General Public License Design by Interspire