Almost all programs on UNIX and/or Linux use shared libraries. Only some programs, like the root shell, /sbin/sh
, on old versions of Solaris, used to be statically linked. It is no longer the case for the current Solaris releases. It was mainly due to historical reasons when disks used to be small in size (usually 128MB or less in size) and the shared libraries in /usr/lib
were mounted from a second disk or NFS server. If you boot a server into single-user mode, it may not mount partitions other than the root partition, thereby breaking any dynamically linked program.
The ldd
porgram can be used to display shared libraries used a by program, along with the path of the shared libaries.
The following program shows the dependencies of the ls
program on Ubuntu.
1 2 3 4 5 6 7 8 9 10 |
$ ldd /bin/ls linux-vdso.so.1 => (0x00007fffa8ebc000) libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f9b76dbb000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f9b76bb3000) libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f9b769aa000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9b765ea000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9b763e6000) /lib64/ld-linux-x86-64.so.2 (0x00007f9b76fec000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9b761c8000) libattr.so.1 => /lib/x86_64-linux-gnu/libattr.so.1 (0x00007f9b75fc3000) |
If the program’s path is defined in the $PATH
environment variable, then you do not need to specify the full path of the program. You will just need to extract the path by running the which
utility within backticks. This will cause the command within the backticks to be evaluated and the output will be passed to the ldd
command.
1 2 3 4 5 6 7 8 9 10 |
$ ldd `which bash` libcurses.so.1 => /lib/libcurses.so.1 libc.so.1 => /lib/libc.so.1 libsocket.so.1 => /lib/libsocket.so.1 libgen.so.1 => /lib/libgen.so.1 libnsl.so.1 => /lib/libnsl.so.1 libmp.so.2 => /lib/libmp.so.2 libmd.so.1 => /lib/libmd.so.1 libcryptoutil.so.1 => /lib/libcryptoutil.so.1 libm.so.2 => /lib/libm.so.2 |