Oct 21, 2023 4 min read

How to use ldd Command on Linux?

Use the ldd command in Linux with our step-by-step tutorial. It is a command-line tool displays a list of the shared libraries.

use ldd Command on Linux
Table of Contents

Introduction

Before we begin talking about how to use ldd commands on Linux, let's briefly understand-What is ldd command ?

The ldd command on Linux is a handy tool used to check the shared library dependencies of an executable or shared object file. It helps identify which dynamic libraries are required by a binary and where those libraries are located.

The "ldd (List Down Dependencies)" command-line tool on Linux displays a list of the shared libraries that are needed by each application or command. It also discovered any missing dependencies/libraries for an executable program or command. Resources like classes, functions, values, or subroutines are denoted by the term "libraries".

This tutorial will explain the usage of the ldd command, allowing you to track down missing or mismatched libraries and ensure proper execution of your programs. We will also address a few FAQs on how to use ldd commands on Linux.

Prerequisites

All the most popular Linux distributions come with the "ldd" command line program already installed. However, if you are still utilizing an outdated distribution, run the installation command as follows:

sudo yum install libc-bin                         #For CentOS/RHEL
sudo dnf install libc-bin                         #For Fedora
sudo apt install libc-bin                         #For Ubuntu/Debian

According to the output, "libc-bin" is already running the most recent version (2.35-0ubuntu3.1).

How to use the “ldd” command on Linux?

The syntax of the "ldd" command, which is listed below, determines how it functions:

Syntax:

ldd [option]... file...

The following components are present in the syntax:

  • ldd: This part is used to identify the "ldd" command.
  • option: Displays the options that the "ldd" command supports.
  • file: the designated file whose dependencies must be verified.

By using its "-help" command, the "ldd" command supports a set of practical arguments and options that are simple to access:

ldd --help

The "ldd" command's options list and basic information are displayed in the output mentioned above.

Example 1: Supports Only Absolute Path

Since the "ldd" command is incompatible with the standard command. If the user enters the standard command after the "ldd" character, it displays the outcomes indicated in the screenshot:

ldd ls

Now, use "ldd" to enter the "absolute" path for the "ls" command:

ldd /usr/bin/ls

The shared libraries that the "ls" command depends on are printed in the output.

Note: Use the "which" command, which is specified here, to obtain a command's absolute path:

which ls

Example 2: Display Shared Library Dependencies

To see the shared library dependencies of an executable program or command, run the "ldd" command:

ldd /bin/grep

Use the "-v (verbose)" flag with the "ldd" command mentioned above to get more information about these dependencies, as shown below:

ldd -v /bin/grep

The version information for the "grep" command's shared library dependencies is now displayed in the output.

Example 3: Show the Un-Used Direct Dependency

The unused direct dependencies of the provided command are shown by the "-u" argument of the "ldd" command.

The unused direct dependencies of the "cat" command are seen in this example:

ldd -u /usr/bin/cat

There are no unused direct dependents of the "cat" executable command, as seen by the output printing nothing.

Example 4: Show Missing Dependencies With ldd

The "ldd" command is useful for determining an executable file's missing dependencies. The "rm" command's missing dependencies are discovered in this way:

ldd /bin/rm

The "rm" command's missing requirements are shown below.

FAQs: Using the ldd Command on Linux

How do I use the ldd command? 

To use the ldd command, simply run ldd followed by the path to the executable or shared object file you want to inspect. For example, ldd /path/to/executable.

What information does ldd provide? 

ldd presents a list of the shared library dependencies required by the given executable file. It displays the library's name, its location, and whether it was found or not.

Why is ldd useful?

ldd is useful for troubleshooting missing or mismatched libraries. If an executable fails to run due to a missing library, ldd can help identify which library is missing and where it should be located.

Can I use ldd on any executable file? 

The ldd command works on dynamically linked executables and shared object files. It does not work on statically linked executables, which do not have dependencies on shared libraries.

Can I use ldd recursively to check dependencies of dependencies? 

No, ldd does not recursively check the dependencies of dependencies. It only shows the direct shared library dependencies of the given executable or shared object file.

Is there an option to display additional information with ldd? 

Yes, you can use the -v or --verbose option with ldd to obtain more verbose output, including the library version information and paths that the dynamic linker searches for libraries.

Can ldd be used to display the dependencies of multiple files simultaneously? 

Yes, you can provide multiple file paths as arguments to ldd to display the dependencies of multiple files at once.

Conclusion

The "ldd" command stands for "List Down Dependencies" and it shows executable files or program-shared library dependencies. It also displays "unused" and "missing" dependencies. Additionally, until its absolute path is not defined, it does not function with standard commands.

The aim, function, and goal of the Linux command "ldd" have been clearly demonstrated in this tutorial.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.