2

I have these shared library files in /usr/local/lib:

libopenbabel.so
libopenbabel.so.4
libopenbabel.so.4.0.2

libopenbabel.so is actually a link to libopenbabel.so.4 and libopenbabel.so.4 is actually a link to libopenbabel.so.4.0.2

when I compile my file with this command:

g++ test.cpp -L/usr/local/lib -lopenbabel

and then try to run a.out, I get this error:

./a.out: error while loading shared libraries: libopenbabel.so.4: cannot open shared object file: No such file or directory

Implying that the compiler is finding libopenbabel.so but running into an error when following that link to libopenbabel.so.4 which is in the exact same directory. Any ideas on why this is happening / how I can fix it?

Output of ls -l in /usr/local/lib:

total 33772
drwxr-xr-x  7 root root      4096 Mar 22 01:24 .
drwxr-xr-x 10 root root      4096 Aug 20  2013 ..
drwxr-xr-x  3 root root      4096 Mar 21 23:45 cmake
lrwxrwxrwx  1 root root        13 Mar 21 23:45 libinchi.so -> libinchi.so.0
lrwxrwxrwx  1 root root        17 Mar 21 23:45 libinchi.so.0 -> libinchi.so.0.4.1
-rw-r--r--  1 root root   3315565 Mar 22 01:04 libinchi.so.0.4.1
lrwxrwxrwx  1 root root        17 Mar 21 23:45 libopenbabel.so -> libopenbabel.so.4
lrwxrwxrwx  1 root root        21 Mar 21 23:45 libopenbabel.so.4 -> libopenbabel.so.4.0.2
-rw-r--r--  1 root root  31232420 Mar 22 01:04 libopenbabel.so.4.0.2
drwxr-xr-x  3 root root      4096 Mar 21 23:45 openbabel
drwxr-xr-x  2 root root      4096 Mar 22 01:24 pkgconfig
drwxrwsr-x  4 root staff     4096 Mar  3 12:57 python2.7
drwxrwsr-x  3 root staff     4096 Dec 22 18:25 python3.2
kjh
  • 3,407
  • 8
  • 42
  • 79

1 Answers1

3

Either set your LD_LIBRARY_PATH environment variable to contain /usr/local/lib or add /usr/local/lib to /etc/ld.so.conf and run ldconfig as root.

Also, run ldd a.out to check that dynamic linking works well on your app.

Read ld-linux(8), ldconfig(8), ldd(1)

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • In my `/etc/ld.so.conf` file the line `include /etc/ld.so.conf.d/*.conf` I checked the files in `/etc/ld.so.conf.d` and found a file called `libc.conf` that contains the line `/usr/local/lib` so I think this directory is already being searched by ld. – kjh Mar 22 '14 at 07:52
  • for whatever reason I guess having `/usr/local/lib` in libc.conf didn't make the compiler search in `/usr/local/lib`. after adding the path manually to `/usr/local/lib` and running sudo ldconfig as you said, the program works. Thanks a ton for you help. – kjh Mar 22 '14 at 08:06
  • Try running again `ldconfig -v` as root. Then use `ldd` – Basile Starynkevitch Mar 22 '14 at 12:05