【问题标题】:ASIO without RTTI没有 RTTI 的 ASIO
【发布时间】:2022-12-14 05:17:38
【问题描述】:

我试图在没有 rtti 的情况下使用 ASIO (1.24),但我总是遇到未定义的引用错误。 所以我做了一个简单的测试程序来重现这个问题:

主.cpp:

#define ASIO_STANDALONE
#define ASIO_HEADER_ONLY
#define ASIO_NO_EXCEPTIONS
#define ASIO_NO_TYPEID
#include "asio.hpp"

int main()
{
    asio::io_context io;

    return 0;
}

当它被编译时

g++-12 -o Test -std=c++20 -fno-rtti -fno-exceptions -I../libs/Asio/1.24.0/include Main.cpp

我得到

undefined reference to `void asio::detail::throw_exception<std::system_error>(std::system_error const&)'
undefined reference to `void asio::detail::throw_exception<asio::invalid_service_owner>(asio::invalid_service_owner const&)'
undefined reference to `void asio::detail::throw_exception<asio::service_already_exists>(asio::service_already_exists const&)'

我错过了什么吗?我怎样才能让它编译?

【问题讨论】:

    标签: c++ g++ boost-asio c++20 rtti


    【解决方案1】:

    Boost documentation states 如果你编译没有异常支持,你需要提供一个throw_exception 函数:

    这个宏禁用 Boost 中的异常处理,将所有异常转发给用户定义的非模板版本的boost::throw_exception.但是,除非BOOST_EXCEPTION_DISABLE也被定义,否则用户仍然可以检查异常对象是否有任何在抛出点添加的数据,或者使用boost::diagnostic_information(当然在BOOST_NO_EXCEPTIONS下,用户定义的boost::throw_exception不是允许返回给调用者。)

    我认为这很接近于独立的 Asio

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-05
      • 2016-04-02
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      • 1970-01-01
      • 2011-09-14
      相关资源
      最近更新 更多