- First I built the Boost libraries that require building by going to
/usr/local/boost_1_49_0/and running thebootstrap.sh. This went off alright. - Step (1) created all the
.soand.afiles in/usr/local/boost_1_49_0/stage/lib - I tested linking against a library, say
lboost_regexand#include <boost/regex>in my source code. This also went off alright. -
Finally trying out the example on asio, I tried:
g++ -I/usr/local/boost_1_49_0 MAIN.cpp -o MAIN -L/usr/local/boost_1_49_0/stage/lib -lboost_thread -lboost_system -lpthread
(4) compiled alright. But when I run the program with ./MAIN, I get the following error:
./MAIN: error while loading shared libraries: libboost_system.so.1.49.0: cannot open shared object file: No such file or directory
The
-Loption only sets a compile-time library search path; if you want a shared library to be found at runtime then its directory must be known at runtime.One way to set this with
g++is to pass-rpathto the linker, via the compiler; in your case you could say-Wl,-rpath -Wl,/usr/local/boost_1_49_0/stage/lib. (This embeds the directory in the executable.)Another way is to install the libraries in a place that the linker searches by default (e.g.
/usr/local/libmight be such a place, depending on how the system is configured).Yet another way is to set an environment variable such as
LD_LIBRARY_PATH(Linux or Solaris) orDYLD_LIBRARY_PATH(Mac OS X), to tell the linker where to search when launching executables from the shell where the variable is set.