对 boost asio 的未定义引用

Posted

技术标签:

【中文标题】对 boost asio 的未定义引用【英文标题】:Undefined reference to boost asio 【发布时间】:2020-12-22 15:12:32 【问题描述】:

我在使用opt 模式和Bazelboost 构建时遇到问题。这是我的错误。

bazel-out/k8-opt/bin/src/_objs/wallet/message_store.o:message_store.cpp:function _GLOBAL__sub_I__ZN3mms13message_storeC2ESt10unique_ptrIN4epee9net_utils4http20abstract_http_clientESt14default_deleteIS5_EE: error: undefined reference to 'boost::asio::ssl::error::get_stream_category()'
bazel-out/k8-opt/bin/src/_objs/wallet/wallet_rpc_payments.o:wallet_rpc_payments.cpp:function _GLOBAL__sub_I__ZNK5tools7wallet220get_client_signatureB5cxx11Ev: error: undefined reference to 'boost::asio::ssl::error::get_stream_category()'
bazel-out/k8-opt/bin/src/_objs/wallet/wallet2.o:wallet2.cpp:function _GLOBAL__sub_I__ZN5tools7wallet227default_daemon_address_lockE: error: undefined reference to 'boost::asio::ssl::error::get_stream_category()'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function epee::net_utils::http::http_simple_client_template<epee::net_utils::blocked_mode_client>::set_server(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::optional<epee::net_utils::http::login>, epee::net_utils::ssl_options_t): error: undefined reference to 'boost::asio::ssl::context::operator=(boost::asio::ssl::context&&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function epee::net_utils::http::http_simple_client_template<epee::net_utils::blocked_mode_client>::set_server(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::optional<epee::net_utils::http::login>, epee::net_utils::ssl_options_t): error: undefined reference to 'boost::asio::ssl::context::context(boost::asio::ssl::context_base::method)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function epee::net_utils::http::http_simple_client_template<epee::net_utils::blocked_mode_client>::set_server(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::optional<epee::net_utils::http::login>, epee::net_utils::ssl_options_t): error: undefined reference to 'boost::asio::ssl::context::operator=(boost::asio::ssl::context&&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function std::_Sp_counted_ptr<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >*, (__gnu_cxx::_Lock_policy)2>::_M_dispose(): error: undefined reference to 'boost::asio::ssl::detail::engine::~engine()'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::stream_core::~stream_core(): error: undefined reference to 'boost::asio::ssl::detail::engine::~engine()'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::stream<boost::asio::io_context&>(boost::asio::io_context&, boost::asio::ssl::context&): error: undefined reference to 'boost::asio::ssl::context::native_handle()'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::stream<boost::asio::io_context&>(boost::asio::io_context&, boost::asio::ssl::context&): error: undefined reference to 'boost::asio::ssl::detail::engine::engine(ssl_ctx_st*)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >::stream<boost::asio::io_context&>(boost::asio::io_context&, boost::asio::ssl::context&): error: undefined reference to 'boost::asio::ssl::detail::engine::~engine()'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::shutdown_op, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<boost::system::error_code&> >, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::shutdown(boost::system::error_code&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::shutdown_op, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<boost::system::error_code&> >, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::put_input(boost::asio::const_buffer const&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::shutdown_op, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<boost::system::error_code&> >, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::shutdown(boost::system::error_code&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::shutdown_op, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<boost::system::error_code&> >, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::get_output(boost::asio::mutable_buffer const&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::shutdown_op, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<boost::system::error_code&> >, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::put_input(boost::asio::const_buffer const&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function net::http::client_factory::create(): error: undefined reference to 'boost::asio::ssl::context::context(boost::asio::ssl::context_base::method)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::write_op<boost::asio::const_buffers_1>, boost::asio::detail::write_op<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >, boost::asio::const_buffers_1, boost::asio::const_buffer const*, boost::asio::detail::transfer_all_t, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<boost::system::error_code&> >, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > > >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::write(boost::asio::const_buffer const&, boost::system::error_code&, unsigned long&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::write_op<boost::asio::const_buffers_1>, boost::asio::detail::write_op<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >, boost::asio::const_buffers_1, boost::asio::const_buffer const*, boost::asio::detail::transfer_all_t, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<boost::system::error_code&> >, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > > >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::put_input(boost::asio::const_buffer const&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::write_op<boost::asio::const_buffers_1>, boost::asio::detail::write_op<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >, boost::asio::const_buffers_1, boost::asio::const_buffer const*, boost::asio::detail::transfer_all_t, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<boost::system::error_code&> >, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > > >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::write(boost::asio::const_buffer const&, boost::system::error_code&, unsigned long&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::write_op<boost::asio::const_buffers_1>, boost::asio::detail::write_op<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >, boost::asio::const_buffers_1, boost::asio::const_buffer const*, boost::asio::detail::transfer_all_t, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<boost::system::error_code&> >, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > > >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::get_output(boost::asio::mutable_buffer const&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::write_op<boost::asio::const_buffers_1>, boost::asio::detail::write_op<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >, boost::asio::const_buffers_1, boost::asio::const_buffer const*, boost::asio::detail::transfer_all_t, boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::identity<boost::system::error_code&> >, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > > > >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::put_input(boost::asio::const_buffer const&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::read_op<boost::asio::mutable_buffers_1>, boost::asio::detail::read_op<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >, boost::asio::mutable_buffers_1, boost::asio::mutable_buffer const*, boost::asio::detail::transfer_at_least_t, epee::net_utils::blocked_mode_client::handler_obj> >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::read(boost::asio::mutable_buffer const&, boost::system::error_code&, unsigned long&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::read_op<boost::asio::mutable_buffers_1>, boost::asio::detail::read_op<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >, boost::asio::mutable_buffers_1, boost::asio::mutable_buffer const*, boost::asio::detail::transfer_at_least_t, epee::net_utils::blocked_mode_client::handler_obj> >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::read(boost::asio::mutable_buffer const&, boost::system::error_code&, unsigned long&)'
bazel-out/k8-opt/bin/src/_objs/net/http.o:http.cpp:function boost::asio::ssl::detail::io_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::ssl::detail::read_op<boost::asio::mutable_buffers_1>, boost::asio::detail::read_op<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >, boost::asio::mutable_buffers_1, boost::asio::mutable_buffer const*, boost::asio::detail::transfer_at_least_t, epee::net_utils::blocked_mode_client::handler_obj> >::operator()(boost::system::error_code, unsigned long, int): error: undefined reference to 'boost::asio::ssl::detail::engine::get_output(boost::asio::mutable_buffer const&)'

我的构建文件如下所示。

cc_binary(
    name = "denarii_wallet_cli",
    srcs = [
        "simplewallet.cpp",
        "simplewallet.h",
    ],
    linkopts = [
        "-lssl",
        "-lcrypto",
        "-ldl",
        "-lpthread",
        "-lboost_system",
        "-lboost_thread",
    ],
    deps = [
        "//contrib/epee",
        "//src:cncrypto",
        "//src:common",
        "//src:cryptonote_core",
        "//src:cryptonote_protocol",
        "//src:rpc_base",
        "//src:version",
        "//src:wallet",
        "//src/mnemonics",
        "@boost//:asio",
        "@boost//:chrono",
        "@boost//:filesystem",
        "@boost//:locale",
        "@boost//:program_options",
        "@boost//:system",
        "@boost//:thread",
        "@liblzma",
        "@libreadline",
        "@openssl//:libcrypto",
        "@openssl//:libssl",
        "@qrcodegen",
    ],
)

它在dbgfastbuild 模式下构建良好。所以我不知道为什么这不起作用。如果人们有其他问题我不知道该提供什么,我可以提供更多信息:)

我还看到了其他类似的问题,例如:undefined reference to `boost::system::generic_category()' when adding boost/asio

【问题讨论】:

【参考方案1】:

对于https://github.com/nelhage/rules_boost,您需要包含“@boost//:asio_ssl”才能使其正常工作。 :) 并在上述问题中包含链接器标志。

【讨论】:

以上是关于对 boost asio 的未定义引用的主要内容,如果未能解决你的问题,请参考以下文章

对 boost::timer::auto_cpu_timer 的未定义引用

C ++ BOOST对`boost :: filesystem :: detail :: copy_file的未定义引用

boost/asio/ssl 抛出“未定义的引用”错误

使用 ASIO 和 std::thread 制作 C++11 应用程序时对“pthread_create”的未定义引用错误

Travis CI 上的 Boost 中对 `std::__cxx11::basic_string 的未定义引用

对 boost asio 完成处理程序的右值引用