Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux: executable cannot find shared library

Tags:

linux

gcc

I have compiled casablanca and have put -l:/~/path/to/lib/libcasablanca.so in my CMakeList.txt. I have build my application and I have got no errors. But when I run the executable it says:

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

I have done it on another computer and it seems to work fine.

Does anyone know what is the problem? How to fix this?

I have no administrator access to this machine.

like image 408
thedarkside ofthemoon Avatar asked May 12 '14 12:05

thedarkside ofthemoon


People also ask

How do I find shared libraries in Linux?

In this standard, folders /lib, /usr/lib and /usr/local/lib are the default folders to store shared libraries. The /lib folder has libraries used during the boot time of the system but also used by programs in the /bin folder. Similarly, the/usr/lib folder has libraries used by programs in the /usr/bin folder.

Where does Linux install shared libraries?

According to the FHS, most libraries should be installed in /usr/lib, but libraries required for startup should be in /lib and libraries that are not part of the system should be in /usr/local/lib.

Do shared libraries need executable?

9.2. As shared libraries cannot be directly executed, they need to be linked into a system executable or callable shared object. Hence, shared libraries are searched for by the system linker during the link process. This means that a shared library name must always start with the prefix lib and have the extension .


1 Answers

This is very simple: your library is not in the default system path from them the shared libraries are imported. During the compilation, the compile scripts solved these problems. In runtime, you have the LD_PRELOAD or LD_LIBRARY_PATH environment variables.

For example: an export LD_LIBRARY_PATH=/home/darkside/wunderprog/lib will extend the directoried searched for your libraries with the named directory. If there is your libcasablanca.so, you will get what you want.

Normally I use a /home/<myusername>/lib directory in my useronly accounts and set LD_LIBRARY_PATH from .profile.

like image 183
peterh Avatar answered Oct 10 '22 08:10

peterh