Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Asio standalone in Xcode C++11 without Boost

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.

like image 556
johnbakers Avatar asked Feb 09 '23 15:02

johnbakers


1 Answers

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.
like image 104
zaphoyd Avatar answered Feb 13 '23 03:02

zaphoyd