Check What Libraries an ELF Depends On

Immediate Dependencies Only

1objdump -x a.out | grep NEEDED  # or -p
2
3  NEEDED               libstdc++.so.6
4  NEEDED               libgcc_s.so.1
5  NEEDED               libc.so.6

Alternative:

1readelf -d a.out | grep NEEDED
2
3 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
4 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
5 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

Full Dependencies

1$ ldd a.out
2  linux-vdso.so.1 (0x00007ffff651a000)
3  libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fcc5ef20000)
4  libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fcc5ed00000)
5  libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcc5e900000)
6  libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fcc5e560000)
7  /lib64/ld-linux-x86-64.so.2 (0x00007fcc5f600000)

With hierarchy among shared libraries:

 1$ lddtree a.out
 2a.out => ./a.out (interpreter => /lib64/ld-linux-x86-64.so.2)
 3    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 4        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
 5        ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
 6    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
 7    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
 8
 9$ lddtree -a a.out  # show duplicated dependencies
10a.out => ./a.out (interpreter => /lib64/ld-linux-x86-64.so.2)
11    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
12        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
13            libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
14                ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
15            ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
16        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
17            ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
18        ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
19        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
20            libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
21                ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
22    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
23        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
24            ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
25    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
26        ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2

Note that lddtree can be installed by sudo apt install pax-utils.

Difference

From the top answer of this question :

objdump is simply dumping what the object itself lists as libraries containing unresolved symbols.

ldd is listing which libraries ld.so would actually load. And it follows the graph backward, so that you can see what would be loaded by those libraries.

Additional Sources


Vim: List All Matching Lines
Install & Explain SSL Certificates