Skip to content

Executables and Libraries

Static and dynamic link libraries (or shared object files) are two essential components in modern operating systems.

Linux has very interesting tools to interact with executable files and corresponding libraries. The following quick note comes from the following link.

https://amir.rachum.com/blog/2016/09/17/shared-libraries/

$ readelf -h main

can be used to find header information about the executable.

$ readelf -d main | grep NEEDED

can be used to show the dependency of the executable to libraries.

$ ldd main

will show the dependency hierarchy of an executable.

Each shared library in our dependencies is searched in the following locations, in order:

  1. Directories listed in the executable’s rpath.
  2. Directories in the LD_LIBRARY_PATH environment variable, which contains colon-separated list of directories (e.g., /path/to/libdir:/another/path)
  3. Directories listed in the executable’s runpath.
  4. The list of directories in the file /etc/ld.so.conf. This file can include other files, but it is basically a list of directories – one per line.
  5. Default system libraries – usually /lib and /usr/lib (skipped if compiled with -z nodefaultlib).

$echo $LD_LIBRARY_PATH

can be used to show the current default search paths to find shared libraries.

Published inTools

Be First to Comment

Leave a Reply