Boost logo

Boost Users :

Subject: Re: [Boost-users] [Regex]static compilation problems
From: Esben Mose Hansen (boost_at_[hidden])
Date: 2009-02-15 11:45:14


On Sunday 15 February 2009 16:47:24 Moritz Beber wrote:
> #include <boost/regex.hpp>
>
>
> int main(int , char* [])
> {
>    boost::regex re("\\d+");
>    return 0;
> }
>
> Linking and compiling this with the command:
>
> g++ test.cpp -o test -L ~/libs/boost/lib/ -l boost_regex-gcc43-mt
>
> works without problems, but running it then leads to the following:
>
>  error while loading shared libraries:
> libboost_system-gcc43-mt-1_37.so.1.37.0: cannot open shared object file:
> No such file or directory
>
> But the directory clearly shows its existence:

Indeed, but the dynamic linker (ldd) cannot find it when loading your ELF-file.
There are several solutions to this, namely LD_LIBRARY_PATH, ldconfig, rpath
and static linking.

You can look them all up if you like. In brief, LD_LIBRARY_PATH is by far the
easiest for test development, just set LD_LIBRARY_PATH (environment variable)
to point to the right directory:

EXPORT LD_LIBRARY_PATH=~/libs/boost/lib

(bash syntax). rpath is neat if you use Cmake or autotools, which I would
recommend as soon as you are past the toy stage --- it makes a pointer to the
right library inside the ELF-file, and removes it again when installing. I
wouldn't mess with ldconfig unless you are making distribution like work, and
static linking usually gives more troubles than it is worth, besides wasting
resources.

Hope it helps.

-- 
Kærlig hilsen, Esben


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net