Reputation: 10661
I have a program which requires liblog4cpp
installed to run.
Now, I want the program to run on another machine without liblog4cpp
. So I just find the log4cpp.so
and move it to the same directory of my program. But at running error reported:
error while loading shared libraries: liblog4cpp.so.4: cannot open shared object file: No such file or directory
Am I doing it right? How can I tell the program to find the SO file just beside it?
Upvotes: 8
Views: 24460
Reputation: 9801
assuming that the path where the .so
file/s is available is /path
you can also avoid to export an environment variable and just use
LD_LIBRARY_PATH=/path ./myProgram
beware the fact that if you do:
export LD_LIBRARY_PATH=/path
you are resetting LD_LIBRARY_PATH
to a single value /path
and losing anything you added before to this environment variable. If you want to add a value without losing the previous ones
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path
Upvotes: 7
Reputation: 6526
In the rc script from where you are launching your program, you should set the LD_LIBRARAY_PATH before launching the application. Remember, the .so are the shared libraries, it is required at the run time to link. Thus, it should be available in the standard path like /usr/lib before launching. In case it is not copied in the standard path like /usr/lib then specify the path by using the following.
export LD_LIBRARY_PATH=<new_path_of_so>:$(LD_LIBRARY_PATH)
Ideally, I would have placed this .so in the standard path like /usr/lib. If it is installed in the standard path, then there is no need to set the above path. Remember, to make your program better, put the new path in ldconfig.conf.
You can debug such errors by using the following.
$strace <binary_name>
to know the so dependencies
$ldd <binary_name>
For further, check the below link.
http://www.tune2wizard.com/sharedobject-crash/
Upvotes: 6
Reputation: 1
After adding shared objects (or shared libraries lib*.so*
, or such symbolic links) to system directories like /usr/lib
or /lib
known to the dynamic linker ld-linux.so(8) (or ld.so
) you need to run ldconfig(8)
You could also add them to /usr/local/lib/
but then be sure that /etc/ld.so.conf
(or some file /etc/ld.so.conf.d/*.conf
) .mentions that directory (and run ldconfig
after changing it)
Upvotes: 2
Reputation: 9803
In addition to what others are suggesting, consider adding the file to the dynamic linker's cache. You can do it like this:
ldconfig -l /path/to/lib/liblog4.so.4
To add it to the loader's cache use the following command: ldconfig
Then in order to verify that it was correctly added, run this:
ldconfig -v | grep liblog
Upvotes: 11
Reputation: 2389
Check your LD_LIBRARY_PATH environment variable... One of the directories on the path should point to the location of your log4cpp.so
file; also the linux command ldd
is handy for determining which shared object libraries are being used in your executable. The syntax is ldd <executable>
.
Upvotes: 9
Reputation: 3286
export LD_LIBRARY_PATH
to the path of the library. This env variable works much like the PATH variable. It can contain multiple paths separated by :.
Upvotes: 4