Boost logo

Boost Users :

Subject: Re: [Boost-users] Linker not pulling in boost_system properly
From: Vladimir Prus (vladimir_at_[hidden])
Date: 2009-11-20 01:33:50


Jason Sewall wrote:

> I'm having trouble with linking to an installation of Boost. I just
> downloaded boost_1_41_0.tar.bz2, untarred it, and did:
>
> $ ./bootstrap.sh --prefix=/home/sewall/src/boost-1.41.0
> $ ./bjam --prefix=/home/sewall/src/boost-1.41.0 install
>
> Now I've got a project (using autotools+libtool) of my own making that
> uses a number of Boost libraries. After pointing the configure script
> to the right spot for the Boost libraries, I wind up with errors like
> the following:
>
> /bin/sh ../libtool --tag=CXX --mode=link g++ -I../sim/include
> -I/home/sewall/src/boost-1.41.0/include -I/usr/include/libxml2
> -fopenmp -O0 -fno-inline -ggdb -Wall -Wextra -Wno-unused-parameter
> -Wno-enum-compare -o xml-test xml-test.o ../sim/src/libhwm_net.la
> -lrt
> libtool: link: g++ -I../sim/include
> -I/home/sewall/src/boost-1.41.0/include -I/usr/include/libxml2
> -fopenmp -O0 -fno-inline -ggdb -Wall -Wextra -Wno-unused-parameter
> -Wno-enum-compare -o xml-test xml-test.o
> ../sim/src/.libs/libhwm_net.a -L/home/sewall/src/boost-1.41.0/lib
> -lxml2 -lz -lboost_filesystem -lboost_regex -lrt
> /usr/bin/ld: warning: libboost_system.so.1.41.0, needed by
> /home/sewall/src/boost-1.41.0/lib/libboost_filesystem.so, not found
> (try using -rpath or -rpath-link)

I assume there's /home/sewall/src/boost-1.41.0/lib/libboost_system.so.1.41.0 ?

If so, did you try specifying -rpath-link, as the above suggests? In theory,
-L only affects search for libraries specified with -l. However, if such a library
refers to another one, the linker will try to find that library to check that
there are no unresolved symbols. The -rpath-link option to the linker specifies
where to search.

To see this in action, you can go to tools/build/v2/example/libraries in Boost
source tree, and run "bjam -n" there. Here's the most relevant output (edited
for clarity)

gcc.link app/bin/gcc-4.4.1/debug/app

    "g++" -Wl,-R -Wl,"/home/ghost/.../example/libraries/util/foo/bin/gcc-4.4.1/debug"
   -Wl,-rpath-link -Wl,"/home/ghost/.../example/libraries/util/foo/bin/gcc-4.4.1/debug"
   -o "app/bin/gcc-4.4.1/debug/app"
   -Wl,--start-group "app/bin/gcc-4.4.1/debug/app.o" "util/foo/bin/gcc-4.4.1/debug/libbar.so"
   -Wl,-Bstatic -Wl,-Bdynamic -Wl,--end-group -g

> I don't claim to understand libtool terribly well, but I think that
> the xml-test target is pulling in the dependencies of libhwm_net.la,
> which in turn pulls in boost_filesystem and boost_regex. It seems
> that it boost_filesystem is then asking for libboost_system.
> Everything is acting as it should up to this point, but then the
> linker seems to be at a loss to where libboost_system can be found.
>
> If I manually add -lboost_system to the above command line, the target
> builds fine. Of course I can just have my configure script general
> -lboost_filesystem and -lboost_system whenever boost_filesystem is
> needed, but I suspect there's a better way to do it.

I don't claim to understand libtool either, but there should be a way to make it pass
-rpath-link to gcc.

Hope this helps,
Volodya


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