Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to show all shared libraries used by executables in Linux?
We know that a shared library is a library that can be linked to any program at runtime. In order to view all the shared libraries used by an executable we make use of the Linux command utility known as ldd. We can easily locate the shared libraries on a Linux machine, as they usually start with lib* prefix and have extensions like .so (shared object).
Let's first understand and see examples of how to make use of the ldd command that Linux provides us with.
ldd is a command utility that Linux provides us with and is mostly used in case we want to know the shared library dependencies of an executable or even that of a shared library. It displays the dynamic libraries that are required by a program to run successfully.
How ldd Works
The ldd command works by loading the executable in a special way that causes the dynamic linker to resolve and display all the shared library dependencies without actually running the program. It shows the library name, its location on the filesystem, and the memory address where it would be loaded.
ldd Syntax
ldd [OPTION]... FILE...
The [OPTION] placeholder in the above command can be replaced by the flags that the ldd command provides us with, some of the most common ones are −
-v − Print all information including version details
-d − Processes data relocation and reports missing objects
-u − Used to print unused direct dependencies
-r − Processes data and function relocation, reports missing objects and functions
Now that we know a little bit about the ldd command, let's explore a few examples of it where we will display dependencies of an executable and much more.
Examples
Example 1: Viewing Basic Dependencies
ldd /bin/cp
In the above command we are running the ldd command on the executable named cp stored inside the /bin folder on your linux directory.
linux-vdso.so.1 => (0x00007fffaf3ff000) libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003a06a00000) librt.so.1 => /lib64/librt.so.1 (0x0000003a06200000) libacl.so.1 => /lib64/libacl.so.1 (0x0000003a13000000) libattr.so.1 => /lib64/libattr.so.1 (0x0000003a0ea00000) libc.so.6 => /lib64/libc.so.6 (0x0000003a05200000) libdl.so.2 => /lib64/libdl.so.2 (0x0000003a05a00000) /lib64/ld-linux-x86-64.so.2 (0x0000003a04a00000) libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003a05600000)
Example 2: Finding Unused Dependencies
We can also display the unused direct dependencies of an executable with the help of the -u flag:
ldd -u /bin/cp
Unused direct dependencies: /lib64/libselinux.so.1 /lib64/librt.so.1 /lib64/libacl.so.1 /lib64/libattr.so.1
Example 3: Verbose Output
To get detailed information about library dependencies, use the -v flag:
ldd -v /bin/ls
Understanding the Output
The output format shows:
Library name − The name of the shared library
Arrow (=>) − Points to the actual library file location
File path − Full path where the library is located
Memory address − Virtual address where the library will be loaded
Key Points
lddshould never be used on untrusted executables as it may execute the programThe command helps in debugging missing library errors
It's useful for understanding application dependencies before deployment
Some libraries like
linux-vdso.so.1are virtual and provided by the kernel
Conclusion
The ldd command is an essential tool for Linux system administrators and developers to examine shared library dependencies of executables. It helps troubleshoot missing library errors, optimize application deployment, and understand the runtime requirements of programs on Linux systems.
