Error loading shared libraries
I'm running eclipse on Ubuntu using a g++ compiler and I'm trying to run a sample program that utilizes xerces.
The build produced no errors however, when i attempted to run the program, I would receive this error:
error while loading shared libraries: libxerces-c-3.1.so: cannot open shared object file: No such file or directory
libxerces-c-3.1.so
is in the directory /opt/lib
which I have included as a library in eclipse. The file is there when I checked the folder. When I perform an echo $LD_LIBRARY_PATH
, /opt/lib
is also listed.
Any ideas into where the problem lies? Thanks.
An ldd libxerces-c-3.1.so
command yields the following output:
linux-vdso.so.1 => (0x00007fffeafff000)
libnsl.so.1 => /lib/libnsl.so.1 (0x00007fa3d2b83000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007fa3d2966000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fa3d265f000)
libm.so.6 => /lib/libm.so.开发者_如何学Go6 (0x00007fa3d23dc000)
libc.so.6 => /lib/libc.so.6 (0x00007fa3d2059000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fa3d1e42000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa3d337d000)
Try running ldconfig
as root to see if it solves the problem.
Run ldd libxerces-c-3.1.so
and examine the output to see if all dependencies can be found.
There are many ways to do this, most already mentioned here. BUT you want to avoid accidentally copying your library files into/over those of the system. This is easily done since people have little imagination in making original unique names for their libraries.
So there are a couple of things to think about:
- Do you need these files to be a permanent part of your system?
- Do you only need to install for testing and frequent updates?
- Do you only need them for running that particular command once or twice?
- Where are your native libraries located?
To find your various library locations on your system (apart from using find), look here:
cat /etc/ld.so.conf
cat /etc/ld.so.conf.d/*
On Linux there are some standard places:
/lib # for base system (don't use this!)
/usr/lib # for package manger installed apps
/usr/local/lib # for user installed apps
There are many others, but you should most likely stay with /usr/local/lib
.
Next you need to tell your system where to find these libraries. The cool system dude (who knows what he is doing) way to do this is using ldconfig
, however, you may do stuff you regret, if you make a mistake here. The safest way to use that command is by using the flags -v -n
to make the command verbose and to specify what library directory you need to add.
sudo ldconfig -v -n /usr/local/lib/your-uber-libs
Done. But if you only wanna test something, then rather use your LD_LIBRARY_PATH
directly from command line, like this:
LD_LIBRARY_PATH=/usr/local/lib/your-uber-libs ./your_uber_command
Alternatively, add the following to your .bashrc
script.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/your-uber-libs
Now you can run your dynamically linked command.
I copied all the library files from /opt/lib into /usr/lib and the program works now. Thanks for the response.
Try installing the library libxerces-c3.1 as. Use the command mentioned below to install the library.
sudo apt-get install libxerces-c3.1
This worked like a charm for me.
精彩评论