chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.72k stars 1.19k forks source link

Build with `-DASIO_NO_EXCEPTIONS` and `-DASIO_SEPARATE_COMPILATION` #1464

Open Bolderaysky opened 2 months ago

Bolderaysky commented 2 months ago

As far as I see, it seems to be impossible to build asio with flags ASIO_NO_EXCEPTIONS and ASIO_SEPARATE_COMPILATION as disabling exceptions requires user to provide implementation of template function asio::detail::throw_exception:

#include "asio/detail/throw_exception.hpp"
template <typename Exception>
void asio::detail::throw_exception(
    const Exception &e ASIO_SOURCE_LOCATION_DEFAULTED_PARAM) {
    // Do something
}

It's definetely possible to use template specializations here, but that's not generic way, as it may require user to provide more specializations in case used subset of features changes.

This is my output from linker with both options enabled:

Output ``` mold: error: undefined symbol: void asio::detail::throw_exception(asio::service_already_exists const&) >>> referenced by >>> /tmp/cccF9tyC.ltrans2.ltrans.o:(_sub_I_65535_0.0) mold: error: undefined symbol: void asio::detail::throw_exception(std::system_error const&) >>> referenced by >>> /tmp/cccF9tyC.ltrans1.ltrans.o:(asio::detail::do_throw_error(std::error_code const&, char const*))>>> referenced by >>> /tmp/cccF9tyC.ltrans0.ltrans.o:(std::thread::_State_impl > >::_M_run())>>> referenced by >>> /tmp/cccF9tyC.ltrans0.ltrans.o:(main) mold: error: undefined symbol: void asio::detail::throw_exception(asio::invalid_service_owner const&) >>> referenced by >>> /tmp/cccF9tyC.ltrans2.ltrans.o:(_sub_I_65535_0.0) collect2: error: ld returned 1 exit status make[2]: *** [examples/base/CMakeFiles/examples.base.async.event_loop.dir/build.make:101: examples/base/examples.base.async.event_loop] Error 1 make[1]: *** [CMakeFiles/Makefile2:459: examples/base/CMakeFiles/examples.base.async.event_loop.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... mold: warning: symbol type mismatch: wait >>> defined in /tmp/cckExRqF.ltrans0.ltrans.o as STT_OBJECT >>> defined in /usr/lib/libc.so.6 as STT_FUNC mold: error: undefined symbol: void asio::detail::throw_exception(asio::service_already_exists const&) >>> referenced by >>> /tmp/cckExRqF.ltrans3.ltrans.o:(_sub_I_65535_0.0) mold: error: undefined symbol: void asio::detail::throw_exception(std::system_error const&) >>> referenced by >>> /tmp/cckExRqF.ltrans2.ltrans.o:(asio::detail::do_throw_error(std::error_code const&, char const*))>>> referenced by >>> /tmp/cckExRqF.ltrans0.ltrans.o:(std::thread::_State_impl > >::_M_run()) mold: error: undefined symbol: void asio::detail::throw_exception(asio::invalid_service_owner const&) >>> referenced by >>> /tmp/cckExRqF.ltrans3.ltrans.o:(_sub_I_65535_0.0) collect2: error: ld returned 1 exit status make[2]: *** [examples/base/CMakeFiles/examples.base.async.coroutines.dir/build.make:101: examples/base/examples.base.async.coroutines] Error 1 make[1]: *** [CMakeFiles/Makefile2:430: examples/base/CMakeFiles/examples.base.async.coroutines.dir/all] Error 2 mold: error: undefined symbol: void asio::detail::throw_exception(std::system_error const&) >>> referenced by >>> /tmp/ccnYHmCV.ltrans2.ltrans.o:(asio::detail::do_throw_error(std::error_code const&, char const*))>>> referenced by >>> /tmp/ccnYHmCV.ltrans1.ltrans.o:(std::thread::_State_impl > >::_M_run() [clone .lto_priv.0]) mold: error: undefined symbol: void asio::detail::throw_exception(asio::invalid_service_owner const&) >>> referenced by >>> /tmp/ccnYHmCV.ltrans3.ltrans.o:(_sub_I_65535_0.0) mold: error: undefined symbol: void asio::detail::throw_exception(asio::service_already_exists const&) >>> referenced by >>> /tmp/ccnYHmCV.ltrans3.ltrans.o:(_sub_I_65535_0.0) collect2: error: ld returned 1 exit status make[2]: *** [examples/base/CMakeFiles/examples.base.async.timer.dir/build.make:101: examples/base/examples.base.async.timer] Error 1 make[1]: *** [CMakeFiles/Makefile2:517: examples/base/CMakeFiles/examples.base.async.timer.dir/all] Error 2 mold: error: undefined symbol: void asio::detail::throw_exception(asio::service_already_exists const&) >>> referenced by >>> /tmp/ccv399gK.ltrans3.ltrans.o:(_sub_I_65535_0.0) mold: error: undefined symbol: void asio::detail::throw_exception(std::system_error const&) >>> referenced by >>> /tmp/ccv399gK.ltrans0.ltrans.o:(std::thread::_State_impl > >::_M_run())>>> referenced by >>> /tmp/ccv399gK.ltrans2.ltrans.o:(asio::detail::do_throw_error(std::error_code const&, char const*)) mold: error: undefined symbol: void asio::detail::throw_exception(asio::invalid_service_owner const&) >>> referenced by >>> /tmp/ccv399gK.ltrans3.ltrans.o:(_sub_I_65535_0.0) collect2: error: ld returned 1 exit status ```

Disabling one of the options resolves any issues.