How to List Shared Libraries Used by Executables in Linux

Under a Linux operating system environment, the binary executables associated with the applications/programs you wish to run are directly linked with shared libraries loaded at runtime.

As a curious and evolving Linux user, you will be tempted to get an idea about these shared libraries involved/linked with the binary executables you are running during a normal program startup.

This article will walk us through several approaches to find out all shared libraries used by executables in Linux.

Brief Overview on Linux Libraries

A programmer or a user familiar with the programming world will define a library as pre-compiled code pieces/segments put together in an organized manner/format. The pre-compiled nature/attribute of a library makes it flexibly and easily reusable among different programs.

Under the Linux operating system architecture, we can categorize libraries as either static (static libraries) or shared (shared libraries).

Static libraries are statically bound to a specific program and are only accessible during the program’s compilation time. Shared libraries become active once a program is launched and will reside in memory during the program’s runtime duration.

How to Find a Program’s Shared Libraries in Linux

Before determining the shared libraries associated with your targeted program, you first need to know where the executable associated with your program is residing. In Linux, the location for your programs’ executables is usually inside the /usr/bin directory.

$ ls -l /usr/bin
List All Linux Executable Programs
List All Linux Executable Programs

The column on the far-right lists the names of your programs’ executables.

Find Shared Libraries of Linux Program Using the ldd Command

The ldd command exists as a straightforward shell script that points to a program’s shared libraries. As per the screen capture above, let us for instance attempt to output the shared libraries associated with the anydesk application.

We could determine Anydesk’s executable’s location with the command:

$ whereis anydesk

To determine its shared libraries via the ldd command, we will execute:

$ ldd /usr/bin/anydesk 
Find Shared Libraries of Linux Program
Find Shared Libraries of Linux Program

As you can see, we have a list of numerous libraries associated with anydesk application. Please note that the ldd command tends to execute queried programs to retrieve shared libraries info. Therefore, only associate the command with trusted executables.

Find Program Shared Libraries Using objdump and grep Commands

The objdump command being part of the GNU Binutils package will focus on displaying the object files information whereas the grep command will list the program’s associated shared libraries.

Let us see what these commands will yield for a program like whois used for domain names info.

$ whereis whois 
Find Program Binary Location
Find Program Binary Location

Next, find out the shared libraries of program.

$ objdump -p /usr/bin/whois | grep 'NEEDED'
Find Linux Program Shared Libraries
Find Linux Program Shared Libraries

As you can see, the whois domain lookup program executable is associated with two shared libraries.

Alternatively, you can also use the readelf command to retrieve shared information for the zip program’s executable.

$ whereis zip
$ readelf --dynamic /usr/bin/zip | grep NEEDED
Find Zip Program Shared Libraries
Find Zip Program Shared Libraries

As per the output, the zip program executable is associated with two shared libraries.

Find Shared Libraries Using Awk Command

This option is ideal for a program that is already running. We first need to get it’s PID (Process ID). For instance, let’s say we have the Flameshot screen capture utility running.

To get its PID, we will run:

$ pgrep flameshot 

45261

Our /proc/<pid>/maps file will be transformed to /proc/45261/maps. We can now combine this file with the awk command to retrieve Flameshot executable shared libraries as demonstrated below.

$ awk '$NF!~/\.so/{next} {$0=$NF} !a[$0]++' /proc/45261/maps
Find Shared Libraries Using Awk Command
Find Shared Libraries Using Awk Command

We are now well-acquainted in listing all shared libraries associated with program executables in Linux.

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.