Boost.Asio as header-only

后端 未结 3 1378
攒了一身酷
攒了一身酷 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 <boost/system/error_code.hpp>
    

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

    0 讨论(0)
  • 2020-12-03 11:30

    AFAIK you can get the non-boost version of asio from http://think-async.com/Asio/AsioAndBoostAsio

    "— Boost.Asio uses the Boost.System library to provide support for error codes ( boost::system::error_code and boost::system::system_error). Asio includes these under its own namespace ( asio::error_code and asio::system_error). The Boost.System version of these classes currently supports better extensibility for user-defined error codes.

    — Asio is header-file-only and for most uses does not require linking against any Boost library. Boost.Asio always requires that you link against the Boost.System library, and also against Boost.Thread if you want to launch threads using boost::thread."

    0 讨论(0)
  • 2020-12-03 11:48

    I think bcp pulls the regex library because it can be used (and on Windows machines it is used by default). I expect that you can delete the regex library source files no problem. Make sure you add the correct compiler flags if you are compiler on windows (-DBOOST_DATE_TIME_NO_LIB and -DBOOST_REGEX_NO_LIB)

    The details are from this page (which by the sounds of it you have already found).

    I'm not sure how smart bcp is - I'm don't think you can pass it the defines given above that prevent it following the mscv route.

    0 讨论(0)
提交回复
热议问题