Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

linux
dependencies

How to see library dependencies in Linux

Abdul Monum

The Linux command-line tool provides the ldd command for viewing dynamic dependencies of shared libraries, executable files, and compiled object.o files. The ldd (list dynamic dependencies) command displays the shared libraries that a program (or a shared library) requires to run. The ldd command resolves each library reference (employing the same search conventions as the dynamic linker) and displays the results in the following form:

library-name => resolves-to-path

NOTE: Modern Linux-based versions use the Executable and Linking Format (ELF) shared libraries. ELF supersedes the older a.out and COFF formats.

Using the ldd command

The syntax for the ldd command is as follows:

ldd [option]... file... 

Supported options include:

  • -v: Verbose mode. Print detailed output with all of the information.
  • -u: Print all unused object dependencies.
  • -d: Process data relocation and print missing ELF objects.
  • -r: Process data and function relocation, and print both missing ELF objects and functions.

Example

In the below example, the ldd command prints the shared libraries required by the ls program, which resides in the /bin directory:

ldd /bin/ls

Output:

linux-vdso.so.1(0x00007ffe94eb5000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007fda2039d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fda1ffac000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fda1fd3a000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fda1fb36000)
/lib64/ld-linux-x86-64.so.2 (0x00007fda207e7000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fda1f917000)

Using the -v flag prints a detailed output:

ldd -v /bin/ls

Output:

linux-vdso.so.1 (0x00007fff62a99000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f1552960000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f155256f000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f15522fd000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f15520f9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1552daa000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1551eda000)

Version information:
/bin/ls:
		libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.17) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6
/lib/x86_64-linux-gnu/libselinux.so.1:
		libdl.so.2 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libdl.so.2
		ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
		libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.8) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.7) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6
	/lib/x86_64-linux-gnu/libc.so.6:
		ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
		ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
	/lib/x86_64-linux-gnu/libpcre.so.3:
		libpthread.so.0 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libpthread.so.0
		libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6
	/lib/x86_64-linux-gnu/libdl.so.2:
		ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
		libc.so.6 (GLIBC_PRIVATE) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
	/lib/x86_64-linux-gnu/libpthread.so.0:
		ld-linux-x86-64.so.2 (GLIBC_2.2.5) => /lib64/ld-linux-x86-64.so.2
		ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
		libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.3.2) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
		libc.so.6 (GLIBC_PRIVATE) => /lib/x86_64-linux-gnu/libc.so.6

RELATED TAGS

linux
dependencies

CONTRIBUTOR

Abdul Monum
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring