How to Use LDD Command in Linux

6

In Linux systems, we constantly work with executable files either in the terminal or graphical applications. Executables contain shared libraries, which are files that are shared and reused across programs. In windows, these are typically in the form of DDL files. In Linux, however, they are in the form of .o or .so files.

This guide will show you how to use the ldd command-line utility to show shared objects and the dependencies in an executable.

What is Ldd

Ldd is a powerful command-line tool that allows users to view an executable file’s shared object dependencies. A library refers to one or more pre-compiled resources such as functions, subroutines, classes, or values. Each of these resources is combined to create libraries.

In Linux, library files are commonly located in /lib or /usr/lib directories. Libraries help save time because programs can repurpose and use them as they see fit.

There are two types of libraries:

  • Static libraries
  • Dynamic or Shared Libraries

How to Install The Ldd command

Typically, you will find the ldd command available in almost any Linux distribution. However, in case it is unavailable, you can install it by using the command:

sudo apt-get install libc-bin

With the command installed, we can start using it.

Basic Ldd Command Usage

The general syntax for the ldd command is pretty straightforward. By default, executing the ldd command shows the shared object dependencies.

The syntax is as:

For example, to show the shared library dependencies of the bash binary, we use the command:

The above command shows the dependencies as:

The first section shows a virtual dynamic shared object (VDSO). The second line shows the path of the ELF interpreter that is hardcoded into the executable, and the final part shows the memory at which the library is loaded.

Ldd Options

We use ldd options to modify the behavior of the command. Supported options include:

  • -v – Verbose mode, which prints all information.
  • -u – Shows unused direct dependencies
  • -d – Executes data relocation and shows missing ELF objects.
  • -r – executes data and function relocation and shows missing ELF objects and functions.

Show detailed output

To show the dependencies of a binary with detailed information, we can pass the -v flag to the ldd command as:

How to Use LDD Command in Linux How to Use LDD Command in Linux 1624315170 685 How to Use LDD Command in Linux

Ldd Show Unused Direct Dependencies

Show unused direct dependencies with the -u flag as:

How to Use LDD Command in Linux How to Use LDD Command in Linux 1624315171 957 How to Use LDD Command in Linux

NOTE: Ldd only works with dynamic executables. If used on a non-dynamic executable, it will display an error as:

How to Use LDD Command in Linux How to Use LDD Command in Linux 1624315171 916 How to Use LDD Command in Linux

In Conclusion

This tutorial covered how to use the ldd command in Linux and get shared library dependency information for dynamic executables. If you learned something from this tutorial, share it with others.

If you are looking for detailed information, consider the following man pages:

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More