Boost: introduction and installation of boost library

Posted by numtre on Wed, 05 Jan 2022 21:26:16 +0100

1. Introduction to boost library

Boost is a powerful, exquisitely constructed, cross platform, open source and completely free C + + library. It was initiated and established by Beman G.Dawes in 1998. Many modern C + + programming technologies are used, covering string processing, regular expressions, containers and data structures, concurrent programming, functional programming, generic programming, design pattern implementation and many other fields, which greatly enriches the functions and expressiveness of C + +, and can make the development of C + + software more concise, elegant, flexible and efficient.

The Boost library can work perfectly with the C + + standard library and provide extended functions for it. Most of the Boost library functions need to include the corresponding header file, and a few need to connect to the library.

1.1 acquisition method

The Boost community provides Linux and Windows versions according to the operation of the target platform, and supports the installation of precompiled versions and source code versions.

# Official website

# Download address

# Precompiled version download address

1.2 code structure

Top structure

boost_1_73_0$ tree -L 1 -d
├── boost                 # The most important directories and documentation
├── doc                   # Documents in HTML format can also be generated in PDF format
├── libs                  # Examples, tests, compiled code, and documentation for all components
├── more                  # Library author related documents
├── status                # It can be used to test various components of the Boost library
└── tools                 # b2, quickbook and other built-in tools

Boost directory structure
The boost subdirectory contains all the library codes we may use. They are placed in different directories according to types. Usually, we only need to care about this directory.

/boost_1_73_0/boost$ tree -d -L 1
├── accumulators          # Accumulator Library
├── algorithm             # Algorithm library
├── align                 # Memory alignment Library
├── archive               # Serialization Library
├── asio                  # Asynchronous concurrent Library
├── assert                # Assertion Library
├── assign                # Assignment initialization Library
├── atomic                # Atomic operation Library
├── beast
├── bimap                # Bidirectional associative array
├── bind                 # bind expression
├── callable_traits
├── chrono               # Time processing library
├── python               # python Library

1.3 mode of use

After installing the environment, you only need to include the header file of the corresponding library in your source code to use most of the Boost libraries. For example:

#include <boost/python.hpp>
#include <boost/python/list.hpp>
#include <boost/python/module.hpp>
#include <boost/assert.hpp>

2. Development environment installation

2.1 Windows environment installation

This section describes how to install a precompiled version of the boost library in a Windows environment_ 1.73.0 as an example.

The installation of precompiled version is relatively simple. Just download and install the specified version.

1. Download boost_1_73_0

The download address of the precompiled version is:

2. Installation

Double click Install in C:\boost_1_73_0

3. Comparison between boost and python versions

The python library will be installed under full installation, and there is a corresponding relationship between the python library and the python version under the current system. You can find the corresponding boost library according to the following table.


2.2 Linux environment installation

Here is how to use source code compilation and installation to boost_ 73 cases were 1.0

1. Download the source code

wget --no-check-certificate

2. Compile and install

tar xvf boost_1_73_0.tar.bz2

cd boost_1_73_0

./b2 --buildtype=complete install

boost has a large number of libraries. In fact, you can choose to install the specified libraries. Here, for convenience, I choose to install them completely.

When installing the boost library, I will install it directly according to the default path. Finally, I will install all compiled libboost * libraries in the / usr/local/lib directory. If you need to specify a path, you can add the path parameter "– prefix=xxx" during compilation. In this case, you need to manually add the path to the environment variable after installation.

If there are multiple Python versions in the system, you can specify the python version by "– with python = Python *". By default, the system default version is used.

3. Custom installation

Complete compilation is time-consuming and laborious, and most libraries may not be used at all in our development process, so users can choose the library to compile by themselves.
The relevant execution commands are as follows:

View all libraries that must be compiled to use

./b2 --show-libraries

On the basis of the full compilation command, use the – with or – without option to turn on or off the compilation of a library, such as:

./b2 --with-date_time --buildtype=complete install

Only data will be compiled and installed_ Time library

3. References

Boost library full development guide

Topics: C++ boost