(I want to make this question as generic as possible, so I will omit the name of the library that gave me the problem in the title.)
I have a project, and for that project I need a library xxx. So I download that library, compiled with the default commands (./configure && make && make install && make clean) - the installation procedure was documented - and tried if the example given in the documentation worked to see whether everything was correctly set up. I copied and pasted the code in a .c file and compiled it with the following command:
gcc -o program program.c -lxxx
And gcc reports no errors. However, as soon as I run the program, the following error occurs:
./program: error while loading shared libraries: lib<xxx>.so: cannot open shared object file: No such file or directory
The first solution that came up to my mind was to use the gcc option -static. It worked fine and the program run correctly. But I was disappointed because that means that the library is "embedded" in the program (sorry for the wrong terminology here: I'm just a student).
So, I looked for a solution in Stack Overflow: that's what I found: error while loading shared libraries: libnsd.so: cannot open shared object file: No such file or directory
The library is different, but using the command
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
worked fine. In fact the libxxx.so is in /usr/local/lib (found just by using ls /usr/local/lib | grep xxx). The other, permanent, solution the thread suggests is to write the directory name in the /etc/ld.so.conf file:
sudo echo "/usr/local/lib" >> /etc/ld.so.conf
sudo ldconfig
And that's the tricky point: ld.so.conf file contains the following line
include /etc/ld.so.conf.d/*.conf
and inside the directory /etc/ld.so.conf.d there is a file called libc.conf that contains the line
/usr/local/lib
I'm a bit confused about that include; if it works just as #include in C I should have /usr/local/lib in my /etc/ld.so.conf file. It appears it is not so.
rehashafter installing the library?