Sunday, April 12, 2009

How To: Fix shared library load problem in GNU/Linux

I recently started learning/using Google C++ Testing framework.

I compiled and installed Google testing framework as per the instruction. But still I wasn't able to run the sample applications compiled by me.

Whenever I run them, I used to get following error.

error while loading shared libraries: cannot open shared object file: No such file or directory

But I had installed Google test framework properly. The install script had properly placed the into /usr/local/lib

So, to check which all shared library are failed to load, I issued following command

$ ldd a.out

and the output was

raghunayak@raghu-desktop:~/google_test/samples$ ldd a.out => not found => /usr/lib/ (0x00002b2897d75000) => /lib/ (0x00002b2898080000) => /lib/ (0x00002b2898301000) => /lib/ (0x00002b2898510000)
        /lib64/ (0x00002b2897b57000)

Which showed that, only libraries placed in /usr/local/lib are failed to load. This gave me a hint that, /usr/local/lib is not the ld library search path.

To confirm this, I entered following command, which lists all the libraries that ld can load.

$ ldconfig -p

This confirmed that, /usr/local/lib is indeed missing from ld library search path.

So, to include /usr/local/lib into the ld library search path, I typed following into the terminal.


after this, I typed

$ ldd a.out

and this time the ld was able to properly find the library placed in '/usr/local/lib'

raghunayak@raghu-desktop:~/google_test/samples$ ldd a.out => /usr/local/lib/ (0x00002ae54f520000) => /usr/lib/ (0x00002ae54f772000) => /lib/ (0x00002ae54fa7d000) => /lib/ (0x00002ae54fcfe000) => /lib/ (0x00002ae54ff0d000)
        /lib64/ (0x00002ae54f302000)

After this I was able to run samples without any problems. :)

Temporary Solution:

Temporary solution is to add '/usr/local/lib' into the environmental variable named LD_LIBRARY_PATH

so, the solution is to add /usr/local/lib into the enviornment variable named LD_LIBRARY_PATH, by typing

You can do this by typing


Permanent solution:

permanent solution is to modify the file /etc/ and add the path /usr/local/lib into it.

You can do it manually by typing

$ sudo gedit /etc/

or type following into the terminal

$ sudo bash -c 'echo /usr/local/lib >> /etc/ ' && sudo ldconfig

P.S.: I think GNU/Linux distributions by default should include /usr/local/lib in /etc/ or at-least the install script of the libraries should have this intelligence.

No comments: