内置和静态链接的升压模块会导致 shutdown_service() 出现一堆链接器错误

Built and static linked boost modules causes a bunch of linker errors with shutdown_service()

本文关键字:链接 service 错误 一堆 shutdown 静态 模块 内置      更新时间:2023-10-16

我正在尝试将选定的提升模块构建到我的代码中,作为静态库来满足我们项目所需的内容。我似乎能够让他们使用他们的 Boost.Build 系统进行构建,我的项目将使用 boost 共享库进行编译,但是当我尝试链接静态时,它们会中断。

我使用以下方法构建了 Boost:

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

哪一个带来成功

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

然后我尝试使用带有自动工具的makefile进行编译:

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

这返回了这个奇妙的错误:

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

我缺少什么才能正确编译它?

问题不在于编译时,而在于它试图链接时。

给出 -l 选项的顺序很重要 因此,尝试将 -lboost_system 作为 -l 选项中的第一个。

-pthread -Wl,-Bstatic -L/home/mike/dev/cpp/boost_1_60_0/stage/lib -lboost_system -lboost_iostreams -lboost_timer -Wl,-Bdynamic