Sunday, April 12, 2009

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

I recently started using Google C++ Testing framework.

I compiled and installed Google testing framework in Linux as per the instructions. 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.

To check which all shared libraries 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 have failed to load. This gave me a hint that /usr/local/lib is not in the LD_LIBRARY_PATH 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 again ran ldd command
ldd a.out

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)

Now I can run samples without any problems. :)

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

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/


type following in the terminal
sudo bash -c 'echo /usr/local/lib >> /etc/ ' && sudo ldconfig

Technorati tags: , .


Anonymous said...

Thank you for this concise, brief, and straight-forward tutorial about fixing missing linked libraries! It was very helpful!

Dinesh said...

Thank You... I was missing the same ld library from my patht too...