Charles Noon
Charles Noon

Reputation: 601

Header-only asio standalone

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.

Upvotes: 4

Views: 13570

Answers (2)

bplotka
bplotka

Reputation: 141

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>

Upvotes: 13

Tanner Sansbury
Tanner Sansbury

Reputation: 51931

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:


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.

Upvotes: 11

Related Questions