ldconfig is a program that is used to maintain the shared library cache. This cache is typically stored in the file
/etc/ld.so.cache and is used by the system to map a shared library name to the location of the corresponding shared library file. This is used when a program is executed to find locations of shared libraries that need to be dynamically loaded and linked to the program. By default, the shared library files in
/usr/lib and a few other standard directories are maintained in the cache by ldconfig.
A new program or library might be installed in a non-standard directory, for example in
/opt/foobar/lib. Programs that need the shared libraries from this library might fail with this error when executed:
hello-world-program: error while loading shared libraries: libFoobar.so.1: cannot open shared object file: No such file or directory
libFoobar.so.1 might be located in
/opt/foobar/lib, but the system does not know this, so it cannot successfully load and execute the program.
To fix this problem, we need to add the library directory to the list used by ldconfig. There are two ways to do this: just add to
LD_LIBRARY_PATH or rebuild cache.
Add to LD_LIBRARY_PATH
Set this at shell for temporary use or add to the shell initialization file for permanent effect:
- Open the
sudoand add a new line with the library directory. In this case, we add
Rerun ldconfig to rebuild the cache:
$ sudo ldconfig
- Check if the shared library cache now includes the shared libraries from the new directory:
$ ldconfig -p
Your program should now execute without any errors 🙂
Tried with: Ubuntu 14.04