19

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.6 (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)
guntbert
  • 492
  • 6
  • 17
user459811
  • 2,626
  • 9
  • 32
  • 61
  • Possible duplicate of [Linux error while loading shared libraries: cannot open shared object file: No such file or directory](http://stackoverflow.com/questions/480764/linux-error-while-loading-shared-libraries-cannot-open-shared-object-file-no-s) – Oleg V. Volkov Mar 01 '16 at 18:31

5 Answers5

29

Try running ldconfig as root to see if it solves the problem.

Peter O.
  • 28,965
  • 14
  • 72
  • 87
ipk
  • 301
  • 3
  • 2
  • 3
    I tried running `sudo ldconfig` but it still doesn't work – Nubcake Apr 23 '17 at 16:47
  • Of course it didn't @Nubcake. Do this `echo /opt/lib > /etc/ld.so.conf.d/my-bonus-library-path.conf` or suitable equivalent for your case, as root. Then `ldconfig`. [`ld.so`](https://www.man7.org/linux/man-pages/man8/ld.so.8.html) needs to know where to look for libraries; and it uses a cache, ldconfig rebuilds that cache. – ulidtko Apr 27 '21 at 13:18
4

Run ldd libxerces-c-3.1.so and examine the output to see if all dependencies can be found.

Sarge
  • 2,367
  • 2
  • 21
  • 36
  • I've edited the topic with the result from an ldd command. I'm fairly new to linux so I'm not quite sure what the output means. How do I know if I have all the shared libraries required? Are those the ones listed with the arrows? – user459811 Dec 23 '10 at 00:53
3

I copied all the library files from /opt/lib into /usr/lib and the program works now. Thanks for the response.

user459811
  • 2,626
  • 9
  • 32
  • 61
2

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.

v3nM
  • 864
  • 1
  • 12
  • 19
2

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.

not2qubit
  • 10,014
  • 4
  • 72
  • 101