Linker not pulling in boost_system properly

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) /home/sewall/src/boost-1.41.0/lib/libboost_filesystem.so: undefined reference to `boost::system::get_system_category()' /home/sewall/src/boost-1.41.0/lib/libboost_filesystem.so: undefined reference to `boost::system::get_generic_category()' 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. Is there something I should have added to my Boost build to have it know to look for boost_system in /home/sewall/src/boost-1.41.0? Thanks, Jason P.S. I have added /home/sewall/src/boost-1.41.0 to my LD_LIBRARY_PATH, if that helps.

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

On Fri, Nov 20, 2009 at 1:33 AM, Vladimir Prus
I assume there's /home/sewall/src/boost-1.41.0/lib/libboost_system.so.1.41.0 ?
Yes, indeed.
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.
If I add -rpath-link, it does indeed work. However, what I don't understand is why the -R flag that is in the dependency_libs in libhwm_net.la does not appear in the command line above. Libtool appears to be stripping it out, and I can't figure out why. I probably should ask over on their list. Thanks for the help!
participants (2)
-
Jason Sewall
-
Vladimir Prus