Loader not finding shared library in same directory


I had an executable file that executed correctly on a computer. On a different computer with same setup, the dynamic loader that tries to load the shared libraries required by this executable would fail with this error:

error while loading shared libraries: libmatrixio.so: cannot open shared object file: No such file or directory

The surprising part is that the libmatrixio.so shared library file was always present in the same directory as the executable in both computers! It executed on one, but failed to find that file on another computer!


It turns out that the dynamic loader ld.so on Linux does not look in the current working directory by default. To make it look in the current directory, you need to add . to LD_LIBRARY_PATH. More information on this can be found in the ld.so manpage, look for LD_LIBRARY_PATH. After making this change to the shell environment variable, the executable loaded correctly on the other computer.

Tried with: Ubuntu 14.04