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
Related
Which Boost libraries are header-only? And which require building libraries?
Does such a list exist?
The list of libraries that require building is here for Unix-like systems, and here for Windows.
For the current release, 1.58, both are the same:
Boost.Chrono
Boost.Context
Boost.Filesystem
Boost.GraphParallel
Boost.IOStreams
Boost.Locale
Boost.MPI
Boost.ProgramOptions
Boost.Python
Boost.Regex
Boost.Serialization
Boost.Signals
Boost.System
Boost.Thread
Boost.Timer
Boost.Wave
A few libraries have optional separately-compiled binaries:
Boost.DateTime
Boost.Graph
Boost.Math
Boost.Random
Boost.Test
Boost.Exception
Note that some libraries may depend on these (for example, Asio depends on System as pointed out in the comments), so you may still need to build something even if the library you want isn't on the list.
Actually, even ./bootstrap.sh --show-libraries is somewhat incorrect too, because some libraries depend on that listed libraries.
It is possible to get list of header-only libraries with the Boost BCP tool, launching the tool on every library and removing those linking any binaries. That is what was done in How To Build Header Only Boost.
For Boost 1.67.0 the resulting list was:
accumulators
align
any
array
assert
assign
bind
callable_traits
circular_buffer
compatibility
concept_check
config
container_hash
conversion
convert
core
crc
detail
disjoint_sets
dynamic_bitset
endian
foreach
format
function
functional
function_types
fusion
geometry
gil
hana
heap
hof
icl
integer
interprocess
intrusive
io
iterator
lambda
lexical_cast
locale
local_function
logic
metaparse
move
mp11
mpl
msm
multi_array
multi_index
optional
phoenix
poly_collection
polygon
predef
preprocessor
property_tree
proto
ptr_container
qvm
ratio
rational
scope_exit
signals2
smart_ptr
sort
static_assert
throw_exception
tokenizer
tti
tuple
type_index
typeof
type_traits
units
unordered
utility
uuid
variant
vmd
winapi
xpressive
I think the list above is not accurate even though it's from the official documentation. See https://svn.boost.org/trac10/ticket/13222
Instead you can query the list of libraries that need to be built:
> ./bootstrap.sh --show-libraries
The Boost libraries requiring separate building and installation are:
atomic
chrono
container
context
coroutine
date_time
exception
fiber
filesystem
graph
graph_parallel
iostreams
locale
log
math
metaparse
mpi
program_options
python
random
regex
serialization
signals
stacktrace
system
test
thread
timer
type_erasure
wave
Note: On Windows you have to call
bootstrap.bat to build "b2" and then call b2 --show-libraries instead.
I am using a self compiled boost library, have to add libraries for compiling, but I can't tell which boost library should I add in order to use Boost::Algorithm, There is not a clear named library file for it like 'libboost_regex' for "regex" and 'libboost_thread' for "thread".
Only a small number of boost libraries must be built and linked against your application. The list is on their Getting Started page. Here it is:
Boost.Chrono
Boost.Context
Boost.Filesystem
Boost.GraphParallel
Boost.IOStreams
Boost.Locale
Boost.MPI
Boost.ProgramOptions
Boost.Python (see the Boost.Python build documentation before building and installing it)
Boost.Regex
Boost.Serialization
Boost.Signals
Boost.System
Boost.Thread
Boost.Timer
Boost.Wave
As you can see, Boost.Algorithm is not on there. In order to use it, you need only include the header file(s).
Which Boost libraries are header-only? And which require building libraries?
Does such a list exist?
The list of libraries that require building is here for Unix-like systems, and here for Windows.
For the current release, 1.58, both are the same:
Boost.Chrono
Boost.Context
Boost.Filesystem
Boost.GraphParallel
Boost.IOStreams
Boost.Locale
Boost.MPI
Boost.ProgramOptions
Boost.Python
Boost.Regex
Boost.Serialization
Boost.Signals
Boost.System
Boost.Thread
Boost.Timer
Boost.Wave
A few libraries have optional separately-compiled binaries:
Boost.DateTime
Boost.Graph
Boost.Math
Boost.Random
Boost.Test
Boost.Exception
Note that some libraries may depend on these (for example, Asio depends on System as pointed out in the comments), so you may still need to build something even if the library you want isn't on the list.
Actually, even ./bootstrap.sh --show-libraries is somewhat incorrect too, because some libraries depend on that listed libraries.
It is possible to get list of header-only libraries with the Boost BCP tool, launching the tool on every library and removing those linking any binaries. That is what was done in How To Build Header Only Boost.
For Boost 1.67.0 the resulting list was:
accumulators
align
any
array
assert
assign
bind
callable_traits
circular_buffer
compatibility
concept_check
config
container_hash
conversion
convert
core
crc
detail
disjoint_sets
dynamic_bitset
endian
foreach
format
function
functional
function_types
fusion
geometry
gil
hana
heap
hof
icl
integer
interprocess
intrusive
io
iterator
lambda
lexical_cast
locale
local_function
logic
metaparse
move
mp11
mpl
msm
multi_array
multi_index
optional
phoenix
poly_collection
polygon
predef
preprocessor
property_tree
proto
ptr_container
qvm
ratio
rational
scope_exit
signals2
smart_ptr
sort
static_assert
throw_exception
tokenizer
tti
tuple
type_index
typeof
type_traits
units
unordered
utility
uuid
variant
vmd
winapi
xpressive
I think the list above is not accurate even though it's from the official documentation. See https://svn.boost.org/trac10/ticket/13222
Instead you can query the list of libraries that need to be built:
> ./bootstrap.sh --show-libraries
The Boost libraries requiring separate building and installation are:
atomic
chrono
container
context
coroutine
date_time
exception
fiber
filesystem
graph
graph_parallel
iostreams
locale
log
math
metaparse
mpi
program_options
python
random
regex
serialization
signals
stacktrace
system
test
thread
timer
type_erasure
wave
Note: On Windows you have to call
bootstrap.bat to build "b2" and then call b2 --show-libraries instead.
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.
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>