One of the most common errors a programmer faces is when an executable is run and it fails to find a required shared library. The error is usually of this form:
hello-world-program: error while loading shared libraries: libFoobar.so.1: cannot open shared object file: No such file or directory
However, you might know that the shared library file
libFoobar.so.1 actually exists, say in a directory named
/opt/foobar/lib. But, for some reason the ld-linux dynamic loader-linker is not looking in this directory.
It is important to know which are the locations that the loader searches for a given shared library file. This is described in this post. After reading the above post, you can see that the error is caused because the shared library file is not found in the locations listed in that post. Of all those locations, the two places which are easy to modify are at the user-level (
LD_LIBRARY_PATH) and at the system-level (shared library cache).
Set this at shell for temporary use or add to the shell initialization file for permanent effect:
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/foobar/lib
If your shared library is located in the same directory as the executable, then you can add
sudo and add a new line with the library directory. In this case, we add
Rerun ldconfig to rebuild the cache:
Check if the shared library cache now includes the shared libraries from the new directory:
Your program should now execute without any errors.
Tried with: Ubuntu 14.04