Home > other >  ASIO without RTTI
ASIO without RTTI

Time:10-18

I'm trying to use ASIO (1.24) without rtti but I always get undefined reference errors. So I made a simple test program which reproduces the problem:

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;
}

When it gets compiled with

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

I get

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&)'

Is there something I missed? How can I get this to compile?

CodePudding user response:

The Boost documentation states that you need to supply a throw_exception function if you compile without exception support:

This macro disables exception handling in Boost, forwarding all exceptions to a user-defined non-template version of boost::throw_exception. However, unless BOOST_EXCEPTION_DISABLE is also defined, users can still examine the exception object for any data added at the point of the throw, or use boost::diagnostic_information (of course under BOOST_NO_EXCEPTIONS, the user-defined boost::throw_exception is not allowed to return to the caller.)

I assume this closely translates to standalone Asio

  • Related