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.
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.
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
-d − Processes data relocation
-u − Used to print unused direct dependencies
-r − Processes data and function relocation
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.
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 => /lib64/libselinux.so (0x0000003a06a00000) librt.so => /lib64/librt.so (0x0000003a06200000) libacl.so.1 => /lib64/libacl.so (0x0000003a13000000) libattr.so.1 => /lib64/libattr.so (0x0000003a0ea00000) libc.so.3 => /lib64/libc.so.3 (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)
We can also display the unused direct dependencies of an executable with the help of the command shown in the example below
ldd -u /bin/cp
Unused direct dependencies: /lib64/libselinux.so.1 /lib64/librt.so.1 /lib64/libacl.so.1 /lib64/libattr.so.1