0

I'm trying to get select boost modules built and into my code as static libraries for what we need for our project. I seem to be able to get them to build using their Boost.Build system, and my project will compile using boost shared libraries, but when I try to link static, they break.

I built Boost using the following:

./b2 link=static variant=release threading=multi --with-iostreams --with-system --with-timer --ignore-site-config

Which give success

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    /home/mike/dev/cpp/boost_1_60_0

The following directory should be added to linker library paths:

    /home/mike/dev/cpp/boost_1_60_0/stage/lib

Then I try to compile using my makefile with autotools:

tunnel_CPPFLAGS = -march=native -pipe -funroll-loops -fomit-frame-pointer -fforce-addr -fprefetch-loop-arrays -Wall -std=c++0x -I/home/mike/dev/cpp/boost_1_60_0/
tunnel_SOURCES = tunneller/tunnel.cpp config.cpp util.cpp tunneller/remoteclient.cpp tunneller/localclient.cpp
tunnel_LDADD = -lcrypto -lssl
tunnel_LDFLAGS = -pthread -Wl,-Bstatic -L/home/mike/dev/cpp/boost_1_60_0/stage/lib -lboost_iostreams -lboost_timer -lboost_system -Wl,-Bdynamic

Which returns this fantastic error:

make  all-recursive
make[1]: Entering directory '/home/mike/dev/cpp/sonar'
Making all in src
make[2]: Entering directory '/home/mike/dev/cpp/sonar/src'
g++  -g -O2 -pthread -Wl,-Bstatic -L/home/mike/dev/cpp/boost_1_60_0/stage/lib -lboost_iostreams -lboost_timer -lboost_system -Wl,-Bdynamic  -o tunnel tunneller/tunnel-tunnel.o tunnel-config.o tunnel-util.o tunneller/tunnel-remoteclient.o tunneller/tunnel-localclient.o -lcrypto -lssl 
tunneller/tunnel-tunnel.o: In function `boost::asio::detail::task_io_service::shutdown_service()':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:322: undefined reference to `boost::system::system_category()'
tunneller/tunnel-tunnel.o: In function `boost::asio::detail::op_queue<boost::asio::detail::task_io_service_operation>::~op_queue()':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:322: undefined reference to `boost::system::system_category()'
tunneller/tunnel-tunnel.o: In function `boost::asio::detail::epoll_reactor::deregister_descriptor(int, boost::asio::detail::epoll_reactor::descriptor_state*&, bool)':
/home/mike/dev/cpp/boost_1_60_0/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
tunneller/tunnel-tunnel.o: In function `boost::asio::detail::reactive_socket_service_base::destroy(boost::asio::detail::reactive_socket_service_base::base_implementation_type&)':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:322: undefined reference to `boost::system::system_category()'
tunneller/tunnel-tunnel.o: In function `boost::asio::detail::reactive_socket_service_base::destroy(boost::asio::detail::reactive_socket_service_base::base_implementation_type&)':
/home/mike/dev/cpp/boost_1_60_0/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
tunneller/tunnel-tunnel.o:/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:322: more undefined references to `boost::system::system_category()' follow
tunneller/tunnel-tunnel.o: In function `_GLOBAL__sub_I__Z14printUsageExitv':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
tunneller/tunnel-tunnel.o: In function `_GLOBAL__sub_I__Z14printUsageExitv':
/home/mike/dev/cpp/boost_1_60_0/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
tunneller/tunnel-remoteclient.o: In function `std::default_delete<tunnel::LocalClient>::operator()(tunnel::LocalClient*) const [clone .isra.247]':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:322: undefined reference to `boost::system::system_category()'
tunneller/tunnel-remoteclient.o: In function `tunnel::RemoteClient::authenticationSuccess()':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:322: undefined reference to `boost::system::system_category()'
tunneller/tunnel-remoteclient.o: In function `tunnel::RemoteClient::RemoteClient(boost::asio::io_service&, boost::asio::ssl::context&, boost::asio::ip::basic_resolver_iterator<boost::asio::ip::tcp>, std::string, std::string, std::string)':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:322: undefined reference to `boost::system::system_category()'
tunneller/tunnel-remoteclient.o:/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:322: more undefined references to `boost::system::system_category()' follow
tunneller/tunnel-remoteclient.o: In function `_GLOBAL__sub_I__ZN6tunnel12RemoteClientC2ERN5boost4asio10io_serviceERNS2_3ssl7contextENS2_2ip23basic_resolver_iteratorINS8_3tcpEEESsSsSs':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
tunneller/tunnel-remoteclient.o: In function `_GLOBAL__sub_I__ZN6tunnel12RemoteClientC2ERN5boost4asio10io_serviceERNS2_3ssl7contextENS2_2ip23basic_resolver_iteratorINS8_3tcpEEESsSsSs':
/home/mike/dev/cpp/boost_1_60_0/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
tunneller/tunnel-localclient.o: In function `tunnel::LocalClient::handleConnect(boost::system::error_code)':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:322: undefined reference to `boost::system::system_category()'
tunneller/tunnel-localclient.o: In function `tunnel::LocalClient::handleConnect(boost::system::error_code)':
/home/mike/dev/cpp/boost_1_60_0/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
tunneller/tunnel-localclient.o: In function `tunnel::LocalClient::handleConnect(boost::system::error_code)':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:322: undefined reference to `boost::system::system_category()'
tunneller/tunnel-localclient.o:/home/mike/dev/cpp/boost_1_60_0/boost/asio/error.hpp:230: more undefined references to `boost::system::system_category()' follow
tunneller/tunnel-localclient.o: In function `_GLOBAL__sub_I__ZN6tunnel11LocalClientC2EPNS_12RemoteClientERN5boost4asio10io_serviceERNS4_2ip23basic_resolver_iteratorINS7_3tcpEEERt':
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/home/mike/dev/cpp/boost_1_60_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
tunneller/tunnel-localclient.o: In function `_GLOBAL__sub_I__ZN6tunnel11LocalClientC2EPNS_12RemoteClientERN5boost4asio10io_serviceERNS4_2ip23basic_resolver_iteratorINS7_3tcpEEERt':
/home/mike/dev/cpp/boost_1_60_0/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
collect2: error: ld returned 1 exit status
Makefile:385: recipe for target 'tunnel' failed
make[2]: *** [tunnel] Error 1
make[2]: Leaving directory '/home/mike/dev/cpp/sonar/src'
Makefile:355: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/mike/dev/cpp/sonar'
Makefile:296: recipe for target 'all' failed
make: *** [all] Error 2

What am I missing to get this to compile properly?

7
  • I'm not convinced that it is. That was solved quickly by linked the boost_system library. In my case, the linker finds the file, but even though the file is linked I still get these errors. Commented Feb 23, 2016 at 20:54
  • Did you check out the last comment in the accepted answer? Namely the part where -lboost_system etc. was added to what in your case would be tunnel_LDADD instead of tunnel_LDFLAGS. You should be adding them to tunnel_LDADD, since they are static libs. See also here for what these variables mean.
    – ldav1s
    Commented Feb 23, 2016 at 21:14
  • If I put the whole line there including the -Wl,-B,static stuff I get the makefile error "src/Makefile.am:14: error: linker flags such as '-Wl,-Bstatic' belong in 'tunnel_LDFLAGS'" Commented Feb 23, 2016 at 21:20
  • It seems to work if I do this: tunnel_LDADD = /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_system.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_timer.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_iostreams.a -lcrypto -lssl - As long as it works I do not mind it being marked as duplicate lol! Commented Feb 23, 2016 at 21:32
  • You should be able to get rid of -Wl,-Bstatic and -Wl,-Bdynamic. All those flags do is toggle off/on dynamic linking. Your explicit paths imply something like: tunnel_LDADD = -lboost_system -l boost_timer -lboost_iostreams -lcrypto -lssl tunnel_LDFLAGS = -pthread -L/home/mike/dev/cpp/boost_1_60_0/stage/lib could be a little neater.
    – ldav1s
    Commented Feb 23, 2016 at 21:46

1 Answer 1

0

The problem is not when compiling, it is when it trying to link.

The order in which -l option is given matters So, try giving -lboost_system as first in -l options.

-pthread -Wl,-Bstatic -L/home/mike/dev/cpp/boost_1_60_0/stage/lib -lboost_system -lboost_iostreams -lboost_timer -Wl,-Bdynamic
1
  • Thanks for responding. I gave that a shot to re-arrange it, and it actually gave precisely the same output! Here is the compile line autotools produced: g++ -g -O2 -pthread -Wl,-Bstatic -L/home/mike/dev/cpp/boost_1_60_0/stage/lib -lboost_system -lboost_iostreams -lboost_timer -Wl,-Bdynamic -o tunnel tunneller/tunnel-tunnel.o tunnel-config.o tunnel-util.o tunneller/tunnel-remoteclient.o tunneller/tunnel-localclient.o -lcrypto -lssl Commented Feb 23, 2016 at 14:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.