Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Header-only asio standalone

Tags:

boost-asio

Sorry in advance for a kind-of-dumb question - I'm pretty new to all this.

So I downloaded asio from here, and tried to #include asio.hpp, but got the following error;

fatal error: boost/config.hpp: No such file or directory

I thought this was rather odd, as it was suppose to be independent of Boost. I poked around a bit, and saw that I needed to define ASIO_STANDALONE, which I promptly did, only to be met with more errors where it tried to #include something else from Boost.

Is there just a big list of all the things I have to #define to tell it to be standalone or something? That would be very helpful.

like image 686
Charles Noon Avatar asked Nov 29 '22 15:11

Charles Noon


2 Answers

This is an old question, however i had the same problem currenlty with Visual Studio 2013 and Asio 1.10.6. In Visual there is no switch nor compiler flag for c++11 features.
Even with #define ASIO_STANDALONEAsio requires Boost.

Solution is to manually specify that our compiler is c++11 compliant. Just add:

#define ASIO_STANDALONE 
#define ASIO_HAS_STD_ADDRESSOF
#define ASIO_HAS_STD_ARRAY
#define ASIO_HAS_CSTDINT
#define ASIO_HAS_STD_SHARED_PTR
#define ASIO_HAS_STD_TYPE_TRAITS

#include <path_to_asio/asio.hpp>
like image 165
bplotka Avatar answered Dec 18 '22 12:12

bplotka


As noted on the Asio website:

When using a C++11 compiler, most of Asio may now be used without a dependency on Boost header files or libraries. To use Asio in this way, define ASIO_STANDALONE on your compiler command line or as part of the project options.

Thus even when ASIO_STANDALONE is defined, Asio will use Boost when:

  • Using a non-C++11 compiler.
  • When using certain features, such as stackful coroutines that are based on the Boost.Coroutine library.

With asio-1.10.2, the following program:

#include <asio.hpp>

int main()
{
  asio::io_service io_service;
}

compiles with gcc 4.8.1, using -DASIO_STANDALONE -std=c++11 compiler flags. Without specifying the compiler to use c++11, compilation fails when attempting to include Boost header files.

like image 21
Tanner Sansbury Avatar answered Dec 18 '22 13:12

Tanner Sansbury