Fix the “error while loading shared libraries: cannot open shared object file: No such file or directory” error

Yet another c++ error that isn’t immediate to recover: I wanted to compile and run a program that uses the awesome Boost libraries, but after successfully compiling the program against the libraries I managed to download and install I got the error in the title.

After some googling, I found that you have to add the path to the boost libraries to the environment variable LD_LIBRARY_PATH. You can check whether that’s the problem you have by running your program in a shell like this:

export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH

Replace /usr/local/lib/ with the path you chose to install boost libraries to (that’s the default path if you installed them as root).

If your program runs fine, there’s your problem!

To make changes permanent in Ubuntu you have to add a new configuration file for ldconfig:

sudo vim /etc/

(my editor of choice is VIM, and the name of the file itself doesn’t matter)
Add the library path to that file, i.e. /usr/local/lib/.
Save the file, quit and reload your configuration by calling

sudo ldconfig

Note that your LD_LIBRARY_PATH won’t change, but your program will now run!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s