Is there a way to get Asio working without Boost? - c++

I know there is a version of ASIO that is not included in the Boost namespace, but even then ASIO depends on Boost, but I'm wondering if there is a way to get ASIO to work without dependencies on Boost (because I cannot include Boost into the project, for too many reasons).

No, i don't believe so. ASIO has been using boost for as long as i have heard of it. I think they're very much interconnected. But you may be interested in a tool, bcp, which lets you extract the minimal subset of boost required for the libraries that you want to use.

There is also a non-boost version of Asio:
Asio comes in two variants: (non-Boost) Asio and Boost.Asio.
See:
http://think-async.com/Asio/

The "non-boost asio" has its own thread bits instead of using boost.thread, but it still requires boost.date_time, boost.array, boost.utility, boost.bind, boost.shared_ptr...
There is no version of Asio that can work without any Boost dependency.

Recent ASIO versions can work without Boost in a standalone mode. This mode was probably enabled by the C++11 support of the library because it can now use standard threads, futures, etc instead of their Boost implementation. You can simply include ASIO like below and enjoy:
#define ASIO_STANDALONE
#include <asio.hpp>

Related

Boost.Asio without Boost.System

On the Boost System page it is stated that:
The Boost System Library is part of the C++11 Standard Library.
But a number of Boost libraries, such as Asio, depend on Boost System. Is it possible to use the C++11 std stuff instead of Boost System to work with Asio?
AFAIR you can configure Boost System to be header-only
Source: http://www.boost.org/doc/libs/1_66_0/libs/system/doc/reference.html
Other than that, you might simply use Non-Boost Asio

Can we use BOOST_SPIRIT_THREADSAFE flag always when read_json is used in multiple threads without linking with boost.thread libraries?

We are using boost in our project. We are not linking any boost libraries but we are including boost header files like boost/property_tree/ptree.hpp.
We are calling read_json from multiple threads (not boost threads but posix threads) and we are getting crashes at read_json() function. Now we included BOOST_SPIRIT_THREADSAFE before including header files as boost json parser is not thread safe and every thing is working fine. But our reviewer is not accepting this change and he is pointing to the below link
http://www.boost.org/doc/libs/1_60_0/libs/spirit/classic/doc/grammar.html
As this page mentioned "On the other hand, if a grammar
is intended to be used in multithreaded code, we should then define
BOOST_SPIRIT_THREADSAFE before including any spirit header files. In this
case it will also be required to link against Boost.Threads"
But do we really need to link with the Boost.Threads library as we are not using boost threads and my understanding is boost threads internally will use posix threads on Linux platform. Can any one please let me know if I am wrong.
The reviewer is linking to "1.60.0" documentation... of Classic Spirit.
Spirit classic has been obsolete for a decade or more.
What's more, Boost Property Tree has rewritten it's parsers: it doesn't use Spirit at all in 1.60.0. This has been the case for some versions.
Note there can be issues when using Property Tree outside the main entry-point, see e.g.:
boost::property_tree::info_parser breaks on spaces in value

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.
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.

Boost.Asio as header-only

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 asio pulls a very many libraies some of which are with sources so need compiling, bjam etc.
Can I somehow use ASIO in project as only headers, without libs/source? I only need ASIO, not other part of Boost.
EDIT: ASIO want Boost.System which has a lib to link - can this dependency not be so that I can use header only ASIO?
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."
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...)
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.

Creating a multithreading application in vc6 with boost library?

Is it possible to create a multithreading application in VC6 with boost library?
If it is possible, what are some relevant tutorials.
Yes, I have done this successfully, but with Boost v1.30.0. So if you have trouble with the latest versions of the Boost libraries, you might want to go back a year or five. I recall I started getting all sorts of internal compiler errors, et al., when trying to upgrade Boost -- so I didn't, but rather went on using v1.30.0 until I was able to upgrade Visual C++ as well. Even the old versions of Boost are very stable and useful, they just have less features.
http://www.boost.org/doc/libs/1_37_0/doc/html/thread.html
A quick google for "boost thread example" turns up lots of good hits.
The Boost.Thread library provides thead creation and manipulation facilities. Read the boost documentation (link was provided in litb's answer). It also provides synchronization bojects (mutexs). Boost is cross platform and is compatible with VS6.
As for the rest of the boost libraries - they are usually thread safe, but read the documentation of each particular library of details.