Search code examples
c++boostshared-librariesroot

"Error while loading shared libraries" raised when linking boost library, except I cannot use root access to fix it


I am trying to run some code on my school's super computer, running on Ubuntu. That code happens to require the timer library in boost.

So I uploaded the boost 1.71.0 repository, built it succesfully.

Then I built it with the following command (successfully) g++ -g src/foo.cpp -o run/foo -I ../boost_1_71_0/ -L ../boost_1_71_0/stage/lib/ -lboost_timer -fopenmp -std=c++11

Then when I try to run the file, this happens: Error while loading shared libraries: libboost_timer.so.1.71.0: cannot open shared object file: No such file or directory

I scrolled through several forum discussions, and apparently running the following command should update the library path and fix everything: sudo /sbin/ldconfig -v But since I have no root access, I cannot run it. I'm looking for a workaround that doesn't involve any sudoing.


Solution

  • You can run your program by ensuring ../boost_1_71_0/stage/lib/ is in LD_LIBRARY_PATH so the dynamic loader knows where to search for the Boost shared libraries. Run your program as follows, assuming the Boost libraries are located at ../boost_1_71_0/stage/lib/ relative from the directory where your program is located on disk.

    LD_LIBRARY_PATH=../boost_1_71_0/stage/lib/ ./program