Boost is a large collection of free, high quality C++ libraries that cover a broad range of topics. It is often considered a "second standard library" for C++, since many common problems in C++ are solved by using Boost.
From boost.org:
Boost provides free peer-reviewed portable C++ source libraries.
We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications. The Boost license encourages both commercial and non-commercial use.
Some Boost libraries have even made their way into the C++11 standard library, and some other, such as Boost.Optional and Boost.Variant, will be a part of C++17.
Boost covers most corners of programming. From the boost tag wiki here on Stack Overflow:
It includes libraries for:
- String and text processing
- Containers
- Iterators
- Algorithms
- Function objects and higher-order programming
- Generic Programming
- Template Metaprogramming
- Preprocessor Metaprogramming
- Concurrent Programming
- Math and numerics
- Correctness and testing
- Data structures
- Image processing
- Input/Output
- Inter-language support
- Memory
- Parsing
- Programming Interfaces
- Miscellaneous
- Broken compiler workarounds
Version | New Libraries | Release Notes | Release Date |
---|---|---|---|
1.10.0 | notes | 1999-12-14 | |
1.11.0 | Rational Number | notes | 2000-02-01 |
1.12.0 | notes | 2000-02-23 | |
1.13.0 | Utility, Type Traits, Call Traits, Compressed Pair | notes | 2000-02-29 |
1.14.0 | notes | 2000-03-05 | |
1.15.0 | Random Number | notes | 2000-06-17 |
1.16.0 | Functional, iterator header | notes | 2000-06-28 |
1.17.0 | Array | notes | 2000-08-03 |
1.18.0 | Graph, Regular Expression | notes | 2000-09-28 |
1.19.0 | Concept Check, Python, Static Assert, Property Map Concepts | notes | 2000-12-10 |
1.20.0 | Conversion | notes | 2001-01-06 |
1.21.0 | Iterator Adaptor, Pool, Test | notes | 2001-03-09 |
1.22.0 | CRC | notes | 2001-05-25 |
1.23.0 | Any, Function, Tokenizer, Special Functions, Octonions, Quaternions | notes | 2001-07-06 |
1.24.0 | Tuple | notes | 2001-08-19 |
1.25.0 | Thread, Bind | notes | 2001-10-01 |
1.26.0 | Common Factor, Preprocessor | notes | 2001-11-30 |
1.27.0 | notes | 2002-02-05 | |
1.28.0 | Lambda, I/O State Saver | notes | 2002-05-15 |
1.29.0 | Date-Time, Dynamic Bitset, Format | notes | 2002-10-10 |
1.30.0 | Filesystem, Optional, Interval, MPL, Spirit | notes | 2003-03-19 |
1.31.0 | enable_if, Variant | notes | 2004-01-26 |
1.32.0 | Assignment, Minmax, Multi-Index, Numeric Conversion, Program Options, Range, Serialization, String, Tribool | notes | 2004-11-19 |
1.33.0 | Iostream, Hash, Parameter, Pointer Container, Wave | notes | 2005-08-11 |
1.34.0 | Foreach, Statechart, TR1, Typeof, Xpressive | notes | 2007-05-12 |
1.35.0 | Asio, Bimap, Circular Buffer, Function Types, Fusion, GIL, Interprocess, Intrusive, Math/Special Functions, Math/Statistical Distributions, MPI, System | notes | 2008-03-29 |
1.36.0 | Accumulators, Exception, Units, Unordered | notes | 2008-08-14 |
1.37.0 | Proto | notes | 2008-11-03 |
1.38.0 | Flyweight, ScopeExit, Swap | notes | 2009-02-08 |
1.39.0 | Signals2 | notes | 2009-05-02 |
1.40.0 | notes | 2009-08-27 | |
1.41.0 | Property Tree | notes | 2009-11-17 |
1.42.0 | Uuid | notes | 2010-02-02 |
1.43.0 | Functional/Factor, Functional/Forward | notes | 2010-05-06 |
1.44.0 | Meta State Machine, Polygon | notes | 2010-08-13 |
1.45.0 | notes | 2010-11-19 | |
1.46.0 | Icl | notes | 2011-02-21 |
1.46.1 | notes | 2011-03-12 | |
1.47.0 | Chrono, Geometry, Phoenix, Ratio | notes | 2011-07-11 |
1.48.0 | Container, Locale, Move | notes | 2011-11-15 |
1.49.0 | Heap | notes | 2012-02-24 |
1.50.0 | Algorithm, Functional/OverloadedFunction, LocalFunction, Utility/IdentityType | notes | 2012-06-28 |
1.51.0 | Context | notes | 2012-08-20 |
1.52.0 | notes | 2012-11-05 | |
1.53.0 | Atomic, Coroutine, Lockfree, Multiprecision, Odeint | notes | 2013-02-04 |
1.54.0 | Log, TTI, Type Erasure | notes | 2013-07-01 |
1.55.0 | Predef | notes | 2013-11-11 |
1.56.0 | Align, TypeIndex | notes | 2014-08-07 |
1.57.0 | notes | 2014-11-03 | |
1.58.0 | Endian, Sort | notes | 2015-04-17 |
1.59.0 | Convert, Coroutine2 | notes | 2015-08-13 |
1.60.0 | VMD | notes | 2015-12-17 |
1.61.0 | Compute, DLL, Hana, Metaparse | notes | 2016-05-13 |
1.62.0 | Fiber, QVM | notes | 2016-09-28 |
1.63.0 | notes | 2016-12-26 | |
1.64.0 | Process | notes | 2017-04-19 |
Most of the Boost libraries are header-only, meaning that there's nothing you have to compile or link to.
Make sure you are getting the most recent version of Boost:
Header-only libraries can then be used by simply including the respective header files.
A few Boost libraries require compilation:
Also, the following libraries have components which must be compiled:
Boost.DateTime
Boost.Graph
Boost.Math
Boost.Random
Boost.Test
Boost.Exception
The source for Boost can be obtained through the download link on the site, which will re-direct to its SourceForge page for the latest version (1.61.0 as of July 2016). This can be unzipped (or un-tared, etc) to a directory (such as C:\local\boost_1_61_0). This directory can then be added to the include path for the software you are building. After this, you can include Boost headers in C++ files with #include <boost/header/path.hpp>
.
The majority of the libraries in Boost are header-only. If you only need these then the above source distribution is all that is needed. However, if you need to use one of the libraries that requires a compiled binary to be built, you will need that as well.
On any system, the most reliable way to get the correct binaries is to build them yourself. These directions are somewhat different for Windows or Linux/Unix/POSIX.
On Windows with Visual Studio, an alternative to building the libraries yourself is to download pre-built libraries from Boost's SourceForge page (1.61.0 as of July 2016). On that page you can select an installer that will install a version for a specific Visual Studio build or the 7-zip file (boost_X_XX_X-bin-all-32-64.7z) that contains the binaries for all the supported Visual Studio versions. Either of these options includes the source/headers as well as the binaries, so there is no need to have downloaded the source distribution above. Once you have it, extract/install to a directory (such as C:\local\boost_1_61_0) and add that directory to your include path, then add the directory containing the binaries that correspond to your version of Visual Studio (e.g. C:\local\boost_1_61_0\lib32-msvc-12.0 for Visual Studio 2013 32-bit projects) to the library path.
(Beginner level; IDE: CLion)
First, install boost from the Cygwin mirror: open the install exe, search for boost, install the packages.
After boost is installed: it will be located in /usr/include/boost
. This is where everything is. All #include
statements will be a path from the boost folder, as in: #include <boost/archive/text_oarchive.hpp>
.
Once you include the boost files of your choice in your .cpp
files, your code will still not compile in your IDE of choice until you link the libraries and tell cmake to search for your downloaded boost code.
In order to get cmake to search for your boost code,
find_package(Boost 1.60.0 COMPONENTS components_you_want)
# for example:
find_package(Boost 1.60.0 COMPONENTS serialization)
Then, include the directories: include_directories(${Boost_INCLUDE_DIRS})
Finally, add your executable and link the libraries:
add_executable(your_target ${SOURCE_FILES})
target_link_libraries(your_target ${Boost_LIBRARIES} -any_missing_boostlibs)
Before starting your program, avoid an error dump by testing to see if boost has been found before including anything or running your code:
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(YourTarget ${SOURCE_FILES})
target_link_libraries(your_target ${Boost_LIBRARIES} -missing_libs)
endif()
I included -missing_libs
because an error you may run into is that some boost library or another might not have been linked, and you must manually add it--for instance, the link I referenced earlier.
All together, a final CMakeLists.txt file might look something like:
cmake_minimum_required(VERSION 3.7)
project(your_project)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp tmap.cpp tmap.h)
find_package(Boost 1.60.0 COMPONENTS serialization)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(your_project ${SOURCE_FILES})
target_link_libraries(your_project ${Boost_LIBRARIES})
endif()