Boost Note 1: Download, compile, install, test

1. Download

The current version is 1.82, download link:
https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/

2. Install the compilation dependency library

The local environment is Ubuntu 22.04, and the following dependent libraries need to be installed, some of which affect the opening of boost-related functions, and some of which affect the compilation process.
Compile the AOSP source code in the local environment, and have installed related dependent libraries. In addition to the ones listed here, other dependent libraries may be required, which can be installed according to the prompts.
sudo apt install icu-devtools libicu-dev libbz2-dev liblzma-dev libzstd-dev python3-dev python2-dev -y

2.1 Decompression

Source code folder after decompression:

boost_1_82_0$ ls
boost            boost.css      bootstrap.sh  index.html  libs             README.md  tools
boost-build.jam  boost.png      doc           INSTALL     LICENSE_1_0.txt  rst.css
boostcpp.jam     bootstrap.bat  index.htm     Jamroot     more             status

2.2 Execute the bootstrap.sh script to generate the b2 compilation tool

1) After executing bootstrap.sh, two files b2 and project-config.jam are added to the source code directory.
2) The b2 tool is used to compile and install the boost library.
(1) Check the help: b2 --help
(2) Compile: b2
(3) Clean: b2 --clean
(4) Install: b2 install
(5) Reconfigure the compilation script: b2 --reconfigure
If the compilation fails or is in progress It is found that some dependent libraries and boost-related modules are missing. After installing the dependent libraries, you need to execute this command to re-detect dependencies and generate compilation scripts.

$ ./bootstrap.sh 
Building B2 engine..

###
###
### Using 'gcc' toolset.
###
###

g++ (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


###
###

> g++ -x c++ -std=c++11 -O2 -s -DNDEBUG builtins.cpp class.cpp command.cpp compile.cpp constants.cpp cwd.cpp debug.cpp debugger.cpp execcmd.cpp execnt.cpp execunix.cpp filesys.cpp filent.cpp fileunix.cpp frames.cpp function.cpp glob.cpp hash.cpp hcache.cpp hdrmacro.cpp headers.cpp jam_strings.cpp jam.cpp jamgram.cpp lists.cpp make.cpp make1.cpp md5.cpp mem.cpp modules.cpp native.cpp object.cpp option.cpp output.cpp parse.cpp pathnt.cpp pathsys.cpp pathunix.cpp regexp.cpp rules.cpp scan.cpp search.cpp startup.cpp subst.cpp sysinfo.cpp timestamp.cpp variable.cpp w32_getreg.cpp modules/order.cpp modules/path.cpp modules/property-set.cpp modules/regex.cpp modules/sequence.cpp modules/set.cpp -o b2
> tools/build/src/engine/b2
Detecting Python version... 2.7
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... /usr
Generating B2 configuration in project-config.jam for gcc...

Bootstrapping is done. To build, run:

    ./b2
    
To generate header files, run:

    ./b2 headers

The configuration generated uses gcc to build by default. If that is
unintended either use the --with-toolset option or adjust configuration, by
editing 'project-config.jam'.

Further information:

   - Command line help:
     ./b2 --help
     
   - Getting started guide: 
     http://www.boost.org/more/getting_started/unix-variants.html
     
   - B2 documentation:
     http://www.boost.org/build/

2.3 Compile and install

1) Execute the b2 command to compile the source code, first detect the compilation dependencies, and then compile according to the dependency configuration.
2) After successful compilation, install: b2 install.
The default installation paths are: /usr/local/include/boost and /usr/local/lib/

$ ./b2
Performing configuration checks

    - default address-model    : 64-bit [1]
    - default architecture     : x86 [1]

Building the Boost C++ Libraries.


    - compiler supports SSE2   : yes [2]
    - compiler supports SSE4.1 : yes [2]
    - has std::atomic_ref      : no [2]
    - has -Wl,--no-undefined   : yes [2]
    - has statx                : yes [2]
    - has init_priority attribute : yes [2]
    - has stat::st_blksize     : yes [2]
    - has stat::st_mtim        : yes [2]
    - has stat::st_mtimensec   : no [2]
    - has stat::st_mtimespec   : no [2]
    - has stat::st_birthtim    : no [2]
    - has stat::st_birthtimensec : no [2]
    - has stat::st_birthtimespec : no [2]
    - has fdopendir(O_NOFOLLOW) : yes [2]
    - has POSIX *at APIs       : yes [2]
    - cxx11_auto_declarations  : yes [2]
    - cxx11_constexpr          : yes [2]
    - cxx11_defaulted_functions : yes [2]
    - cxx11_final              : yes [2]
    - cxx11_hdr_mutex          : yes [2]
    - cxx11_hdr_tuple          : yes [2]
    - cxx11_lambdas            : yes [2]
    - cxx11_noexcept           : yes [2]
    - cxx11_nullptr            : yes [2]
    - cxx11_rvalue_references  : yes [2]
    - cxx11_template_aliases   : yes [2]
    - cxx11_thread_local       : yes [2]

...(检测编译依赖)

Component configuration:

    - atomic                   : building
    - chrono                   : building
    - container                : building
    - context                  : building
    - contract                 : building
    - coroutine                : building
    - date_time                : building
    - exception                : building
    - fiber                    : building
    - filesystem               : building
    - graph                    : building
    - graph_parallel           : building
    - headers                  : building
    - iostreams                : building
    - json                     : building
    - locale                   : building
    - log                      : building
    - math                     : building
    - mpi                      : building
    - nowide                   : building
    - program_options          : building
    - python                   : building
    - random                   : building
    - regex                    : building
    - serialization            : building
    - stacktrace               : building
    - system                   : building
    - test                     : building
    - thread                   : building
    - timer                    : building
    - type_erasure             : building
    - url                      : building
    - wave                     : building

...patience...
...patience...
...found 18844 targets...
...updating 1767 targets...

... (编译源码)

common.copy /home/dev/github/boost/temp/boost_1_82_0/stage/lib/libboost_wave.a
...updated 1767 targets...


The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    /home/dev/github/boost/temp/boost_1_82_0

The following directory should be added to linker library paths:

    /home/dev/github/boost/temp/boost_1_82_0/stage/lib

2.4 Test procedure

After installation, you don't need to specify include and library path, they can be searched automatically when compiling.
The following test programs can be compiled with clion or the command line:

$ g++ -o main main.cpp
#include <string>
#include <iostream>
#include <boost/foreach.hpp>

int main()
{
    
    
    std::string hello( "Hello, world!" );

    BOOST_FOREACH( char ch, hello )
    {
    
    
        std::cout << ch;
    }

    return 0;
}

2.5 CMake dependencies

Use find_package in the cmake script to show references to boost:

find_package(Boost 1.82 REQUIRED COMPONENTS filesystem regex PATHS C:/Boost)
find_package(Boost 1.82 REQUIRED COMPONENTS ALL)
find_package(Boost 1.82 REQUIRED ALL)

Guess you like

Origin blog.csdn.net/yinminsumeng/article/details/130522539