ldd is the useful command to see executable files and shared object dependencies. Files that start with /lib are called libraries. A library helps a program to use common processes without any handling or administration overhead. There are two types of libraries: static and dynamic libraries.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux system commands queries.
In this context, we shall look into how to use the ldd command in Linux.
If you are using an old version of ubuntu, simply run the below apt command to install ldd:
$ sudo apt install libc-bin
Its syntax is shown below:
$ ldd [option]... file...
This command [option] is explained below:
You can use the ldd command with option -v to show detailed information. For example, we will display detailed the dependencies of the ls command by executing:
$ ldd -v /bin/ls
You can use the ldd command with option -u to show unused direct dependencies. For example:
$ ldd -u /bin/grep
You can show the dependencies of cp command by executing the below command:
$ ldd /bin/cp
You can display ldd works only on dynamic executables using -r option:
$ ldd -r /smart/pycharm-community-2017.3.3/bin/pycharm.sh
The Output might look like this:
not a dynamic executable
This output shows a clear message stating that the supplied file is not a dynamic executable.
When we try ldd on a standard command line executable like ls, We need full path to the dynamic executable:
$ ldd ls
Sometimes, the output will look like this:
ldd: ./ls: No such file or directory
We see that ldd states that it cannot find ls.
$ ldd /bin/ls
To determine whether a given executable daemon supports TCP Wrapper or not, run the following command:
$ sudo ldd /usr/sbin/sshd | grep libwrap
If you see an Output such as this:
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f1cc2ac6000)
Then it indicates that the OpenSSH (sshd) daemon supports TCP Wrapper.
We can use the ldd command when an executable is failing because of a missing dependency. Once we found a missing dependency, we can install it or update the cache with the ldconfig command:
$ sudo ldd /bin/mv
Next, We will perform relocations and report any missing objects (ELF only) by typing below command:
$ sudo ldd -d path/to/executable_file
Also, We will perform relocations for both data objects and functions, and report any missing objects or functions (ELF only) by typing below command:
$ sudo ldd -r path/to/executable_file
1. Missing library error
You may encounter missing library error even though the mentioned libraries are available in the new installation path "/opt/newinstall/lib". This is because the system is not aware of this directory to check for libraries. This can be fixed in any of the two ways.
a. Execute the following command:
$ ldconfig -n /opt/newinstall/lib
b. You can see the following include line in /etc/ld.so.conf file:
include ld.so.conf.d/*.conf
So, create a file in /etc/ld.so.sonf.d folder, say newinstall.conf with the following content:
/opt/newinstall/lib
Then, execute:
$ ldconfig
2. Dynamic linker error, can't map cache files
This may be due to the corrupted cache file. This can be resolved by rebuilding the cache file using ldconfig.
$ ldconfig
ldconfig creates the necessary links and cache (for use by the run-time linker, ld.so) to the most recent shared libraries found in the directories specified on the command line, in the file/etc/ld.so.conf, and in the trusted directories (/usr/lib and /lib).
For Examples:
Execute the following command to set up the correct links for the shared binaries and rebuild the cache:
$ ldconfig –v
Execute the following command after the installation of a new shared library will properly update the shared library symbolic links in /lib:
$ ldconfig -n /lib
The following command will print the current cache:
$ ldconfig -p
This article covers how to use ldd command and how to use in linux command line. In fact, the ldd is a command line tool that prints the shared library dependencies of an executable program or shared library. The ldd command can be useful when wanted to find missing dependencies.