Saturday, July 3, 2010

How to check shared libraries used by an application and add news ones?

To check which libraries are used, use the ldd command. ldd prints the shared libraries required by each program or shared library specified on the command line.

ldd /path/to/file

To add new library files, use ldconfig. "ldconfig creates, updates, and removes the necessary links and cache (for use by the run-time linker, to the most recent shared libraries found in the directories specified on the command line, in the file /etc/, and in the trusted directories (/usr/lib and /lib). ldconfig checks the header and file names of the libraries it encounters when determining which versions should have their links updated. ldconfig ignores symbolic links when scanning for libraries."

After adding new libraries (.so) files to /usr/lib, run sudo ldconfig and that should do it.
Check if the newly added files are used by your binaries by running ldd.

An example output:
[dummy-linux ~]$ ldd /bin/ls =>  (0x00007fff005ff000) => /lib64/ (0x0000003538800000) => /lib64/ (0x0000003538000000) => /lib64/ (0x000000353ac00000) => /lib64/ (0x0000003545800000) => /lib64/ (0x0000003537000000) => /lib64/ (0x0000003537400000)
        /lib64/ (0x0000003536800000) => /lib64/ (0x0000003537800000) => /lib64/ (0x0000003545000000)