Boost.Asio as header-only

后端 未结 3 1387
攒了一身酷
攒了一身酷 2020-12-03 11:11

I want to use ASIO library from Boost in my project. Its doc say it can be header-only if regex is not used and SSL not used. However, running bcp for asi

3条回答
  •  广开言路
    2020-12-03 11:26

    UPDATE – 07/25/2019:

    As noted in the comment below by @OleThomsenBuus (thank you!), from Boost 1.69 onward, Boost.System is now header-only, so there's no need to jump through all these hoops to eliminate the need to link with it.

    ORIGINAL ANSWER:

    The accepted answer is 100% effective and recommended, but another option—if you really want/need to use Boost Asio—is to try compiling your application with -DBOOST_ERROR_CODE_HEADER_ONLY. Use of this macro (documented here) should get around the need to link with Boost.System. However, it's worth reading the caveats pointed out in this answer. In particular, you may need to create a 'dummy' CPP file containing:

    #define BOOST_ERROR_CODE_HEADER_ONLY
    #include 
    

    and disable optimization for that file only. (Personally, I didn't need to do this, but YMMV...)

提交回复
热议问题