我试图在没有rtti的情况下使用ASIO (1.24),但我总是得到未定义的引用错误。所以我做了一个简单的测试程序来重现这个问题:
Main.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&)'我错过了什么吗?我怎样才能编译这个呢?
发布于 2022-10-17 14:56:34
如果您毫无例外地支持编译,则需要提供一个Boost文档状态函数:
此宏禁用Boost中的异常处理,将所有异常转发给用户定义的非模板版本的。但是,除非还定义了
BOOST_EXCEPTION_DISABLE,否则用户仍然可以检查抛出点添加的任何数据的异常对象,或者使用boost::diagnostic_information(当然,在BOOST_NO_EXCEPTIONS下,用户定义的boost::throw_exception不允许返回给调用方)。
我认为这将直接转化为独立的Asio。
https://stackoverflow.com/questions/74098761
复制相似问题