4

According to this page, using Asio without Boost should be fairly straightforward, but I still cannot compile any file with an include that looks like any of these:

#include <asio>
#include <asio.hpp>
#include <asio/version.hpp>

I have set my compiler to use c++11 (which it was already doing, though I did switch from gnu++11 to c++11), and I have placed #define ASIO_STANDALONE before the various includes I am trying.

Is there some extra work necessary for accessing c++11 Asio headers beyond this? I just get file not found errors during compilation with any of the above attempts.

Tanner Sansbury
  • 51,153
  • 9
  • 112
  • 169
johnbakers
  • 24,158
  • 24
  • 130
  • 258
  • Just because you set some flags and preprocessor macros doesn't mean that those header files magically change location. They are still in the same location as before. – Some programmer dude Nov 05 '15 at 12:08
  • @JoachimPileborg I understand, but where are the headers? When I use other c++11 standard libraries, I don't have to do anything extra. Is Asio special in that you have to manually find where the headers are located? Or are you saying that I have to manually add these headers from outside the c++11 native environment? – johnbakers Nov 05 '15 at 12:10
  • 1
    What I mean is that ASIO is still a *part* of Boost, even if it doesn't use Boost, and as such the header files are still inside the `boost` subdirectory so you need to do e.g. `#include `. You still need to install Boost. – Some programmer dude Nov 05 '15 at 12:13
  • @JoachimPileborg ahh I didn't realize that. I thought ASIO standalone was available in c++11 natively without any inclusion of boost at all. Thanks for clarification. – johnbakers Nov 05 '15 at 12:14
  • This information is wrong, asio is available in a standalone fashion apart from boost. I can't recall exactly, there's some sort of coupling between asio and boost::system over error code structures, but this can be separated. http://think-async.com/ –  Nov 06 '15 at 01:15
  • Related: http://stackoverflow.com/questions/16082449/asio-without-boost –  Nov 06 '15 at 01:19
  • 1
    @JoachimPileborg see accepted answer, I think your comment is incorrect about requiring Boost to be installed. – johnbakers Nov 06 '15 at 12:12

1 Answers1

9

Asio can be used without Boost if the following conditions are met:

  • C++11 (or later) compiler in C++11 (or later) compile mode. Exactly how to enable this mode varies based on compiler. For GCC/clang use the -std=c++11 flag. For Xcode set the C++ language dialect to C++11 or later in project settings
  • Asio headers are downloaded from think-async.com. Asio is not part of the standard library (yet). It is bundled with Boost and is available standalone from the authors website. How exactly to add Asio to your include path varies based on compiler. For GCC/clang use -I/path/to/asio or place the Asio headers in /use/local/include. Xcode will also read /usr/local/include or you can specify a custom header path in the header search paths section of your project config.
  • #define ASIO_STANDALONE before including Asio headers. This define tells Asio to use the C++11 standard library features for things like error codes, shared pointers, etc rather than using Boost's polyfills.
zaphoyd
  • 2,642
  • 1
  • 16
  • 22
  • FINALLY, THANK YOU ! Where did you find it is required to define ```"ASIO_STANDALONE"``` ? I didn't see this anywhere and it doesn't work without it ... Moreover, I had to link to pthread library for my program to compile (with ```-lpthread``` ) – Maskim Jan 08 '20 at 12:56
  • 1
    @Maskim I found this line "To use Asio in this way, define `ASIO_STANDALONE`..." here at https://think-async.com/Asio/AsioStandalone.html. In addition, there is a line "Changed compile-time feature detection to define `ASIO_STANDALONE` automatically if C++11 or later is detected." in the Revision History for Asio 1.13.0 in http://think-async.com/Asio/asio-1.13.0/doc/asio/history.html. – aafulei Aug 11 '21 at 07:10