Wednesday, October 26, 2016

Solution to "error while loading shared libraries"

I was trying to run a  simple executable that makes use of opencv library, and I encountered an error:
$ ./a.out
./a.out: error while loading shared libraries: cannot open shared object file: No such file or directory

I was certainly able to locate the file manually in the proper directory:
$ find / -name

Very interesting. This is probably because I manually compiled and installed opencv3.1.0 from sources. In any case, here is the solution.

First, we need to look for the shared library path. The system dynamic linker locations are specified in /etc/ file, which probably includes .conf files in /etc/ folder. Each of the .conf files in the folder specifies the system dynamic linker locations, such as /lib/x86_64-linux-gnu.

Also, one can define the shell-variable LD_LIBRARY_PATH to include the directory of the shared library file that needs to be linked.

My case? It was a subtle. I certainly had the library folder included in one of the config files:
$ cat /etc/
# libc default configuration

Yet, I was still getting the error. Why? That's because I needed to manually load config:
$ sudo ldconfig

I guess make install command of opencv did not automatically do this. For more info, please take a look at this document. You also might be interested in loading one-time shared library files without neither of the methods above, from here.

No comments:

Post a Comment