Table of Contents
Introduction
Boost is a set of libraries for the C++ programming language (includes 164 separate libraries as of version 1.76) that provides support for tasks and constructs such as linear algebra, pseudorandom number generation, multithreading, image manipulation, regular expressions, and unit testing. These libraries are licensed under the Boost Software License, which is designed to allow Boost to be used with both free and proprietary software projects.
In this article, we will install Boost on Ubuntu.
Installation is done in 2 ways: installing package from Ubuntu repositories and compiling from source code.
Method-1: Install From Repository
First the package list is updated:
foc@ubuntu22:~$ sudo apt update -y
Then the libboost-all-dev package is installed:
foc@ubuntu22:~$ sudo apt install libboost-all-dev -y
After installation the libraries are in the following directory:
foc@ubuntu22:~$ ls /usr/lib/x86_64-linux-gnu/libboost_*
/usr/lib/x86_64-linux-gnu/libboost_atomic.a
/usr/lib/x86_64-linux-gnu/libboost_atomic.so
/usr/lib/x86_64-linux-gnu/libboost_atomic.so.1.74.0
/usr/lib/x86_64-linux-gnu/libboost_chrono.a
/usr/lib/x86_64-linux-gnu/libboost_chrono.so
...
Installation completed quickly and easily.
Method-2: Install From Source Code
The download link to download Boost is on the official website.
The source code is published as tar.gz, 7z and zip. Right click on the format you want to download and copy the address.
Download the source code by typing the link after the wget command:
foc@ubuntu22:~$ wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz
--2022-12-24 08:19:16-- https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz
Resolving boostorg.jfrog.io (boostorg.jfrog.io)... 54.191.107.121, 35.166.241.227, 35.155.29.5, ...
Connecting to boostorg.jfrog.io (boostorg.jfrog.io)|54.191.107.121|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://jfrog-prod-usw2-shared-oregon-main.s3.amazonaws.com/aol-boostorg/filestore/06/06d4bff547c1948fbdaf59b9d9d1399917ed0eb3?X-Artifactory-username=anonymous&X-Artifactory-repositoryKey=main&X-Artifactory-artifactPath=release%2F1.81.0%2Fsource%2Fboost_1_81_0.tar.gz&X-Artifactory-projectKey=default&x-jf-traceId=607f26edf2ca9a48&response-content-disposition=attachment%3Bfilename%3D%22boost_1_81_0.tar.gz%22&response-content-type=application%2Fx-gzip&X-Amz-Security-Token=FwoGZXIvYXdzEKr%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDIDeVOkz3AqE3wRF8CKdBNVd2Ec%2F5sO63TAPbxkdzdwmaBTkJ7KOrsc2ORfec0bzUdvZZPBrfgT40vu6qtp6e4sI6jGOFgk20wRLfr9%2BNst3DxTYT4FUHTSSJp9NiVAw%2B2Y%2BjBXCr1ca5lKZcK79gs54yJITg7tY%2F25YlSS%2FRpLDjP3vGc1zeHwhEmcS402H%2BbZY7CZc9rgt602lDMPjiefiFmZIxCLvrCPWslfSnXAuiwfdGx5PTwYWOBnExrs5njis3BEfC%2B6HSaBGEY5sDSwDejhcdWrD7gn5j3EorsQhU%2FgB9xzZIu7WqYGT17cdwGrfxXbzRWIPKkhm9LAm%2FRFQIAT2vnuGZxqtW4mEflNKY64%2F015ieF3OpnaWjGzW1KrNEj60nqh1i9N%2BSbTOTK5NrWLY7haL8OlzC1C8bYw8NM2IUZlUB5VU7aRhAaJBaq5tSltBz7oGIuacbHP%2F2%2FLv1RqtJDdE9L9h7Dy9x73O9xyoJ5C80wGCaPij1lrwvbFu5cnu5hP%2BT5IgWWGpEru65glpqgwvEpQl3%2F2c9TQXxcAqGbZLA%2B8Pko3IFa0Y9zr2HOGurpc3Ea6PUUY8x4Dpfk8jE5WvPgJ9plpa8kUw%2BsD1tpP3WEsvxDTIXVeKVOGxrCtDtApayBf9ijc7yMew%2BDlf4G9P3vrZ6NkOdWczZqQBzowNMS1XCV0itgII8hjlKe8wBlI2oBZCtQLxF%2FUKJ9azntftJkngXhAooeeanQYyKm4seXMeDL0LT3kmd8LYwKhbomDMn83mxQ2hOcFk9LIMScgXYzsZJGiNUw%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20221224T081917Z&X-Amz-SignedHeaders=host&X-Amz-Expires=60&X-Amz-Credential=ASIASG3IHPL66R5ET6WZ%2F20221224%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=8da43c18675fbe46229a36ed02a5729ae256c903b30d23252ce30eef9481d51b [following]
--2022-12-24 08:19:17-- https://jfrog-prod-usw2-shared-oregon-main.s3.amazonaws.com/aol-boostorg/filestore/06/06d4bff547c1948fbdaf59b9d9d1399917ed0eb3?X-Artifactory-username=anonymous&X-Artifactory-repositoryKey=main&X-Artifactory-artifactPath=release%2F1.81.0%2Fsource%2Fboost_1_81_0.tar.gz&X-Artifactory-projectKey=default&x-jf-traceId=607f26edf2ca9a48&response-content-disposition=attachment%3Bfilename%3D%22boost_1_81_0.tar.gz%22&response-content-type=application%2Fx-gzip&X-Amz-Security-Token=FwoGZXIvYXdzEKr%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDIDeVOkz3AqE3wRF8CKdBNVd2Ec%2F5sO63TAPbxkdzdwmaBTkJ7KOrsc2ORfec0bzUdvZZPBrfgT40vu6qtp6e4sI6jGOFgk20wRLfr9%2BNst3DxTYT4FUHTSSJp9NiVAw%2B2Y%2BjBXCr1ca5lKZcK79gs54yJITg7tY%2F25YlSS%2FRpLDjP3vGc1zeHwhEmcS402H%2BbZY7CZc9rgt602lDMPjiefiFmZIxCLvrCPWslfSnXAuiwfdGx5PTwYWOBnExrs5njis3BEfC%2B6HSaBGEY5sDSwDejhcdWrD7gn5j3EorsQhU%2FgB9xzZIu7WqYGT17cdwGrfxXbzRWIPKkhm9LAm%2FRFQIAT2vnuGZxqtW4mEflNKY64%2F015ieF3OpnaWjGzW1KrNEj60nqh1i9N%2BSbTOTK5NrWLY7haL8OlzC1C8bYw8NM2IUZlUB5VU7aRhAaJBaq5tSltBz7oGIuacbHP%2F2%2FLv1RqtJDdE9L9h7Dy9x73O9xyoJ5C80wGCaPij1lrwvbFu5cnu5hP%2BT5IgWWGpEru65glpqgwvEpQl3%2F2c9TQXxcAqGbZLA%2B8Pko3IFa0Y9zr2HOGurpc3Ea6PUUY8x4Dpfk8jE5WvPgJ9plpa8kUw%2BsD1tpP3WEsvxDTIXVeKVOGxrCtDtApayBf9ijc7yMew%2BDlf4G9P3vrZ6NkOdWczZqQBzowNMS1XCV0itgII8hjlKe8wBlI2oBZCtQLxF%2FUKJ9azntftJkngXhAooeeanQYyKm4seXMeDL0LT3kmd8LYwKhbomDMn83mxQ2hOcFk9LIMScgXYzsZJGiNUw%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20221224T081917Z&X-Amz-SignedHeaders=host&X-Amz-Expires=60&X-Amz-Credential=ASIASG3IHPL66R5ET6WZ%2F20221224%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=8da43c18675fbe46229a36ed02a5729ae256c903b30d23252ce30eef9481d51b
Resolving jfrog-prod-usw2-shared-oregon-main.s3.amazonaws.com (jfrog-prod-usw2-shared-oregon-main.s3.amazonaws.com)... 52.92.163.9, 52.92.248.225, 52.218.153.3, ...
Connecting to jfrog-prod-usw2-shared-oregon-main.s3.amazonaws.com (jfrog-prod-usw2-shared-oregon-main.s3.amazonaws.com)|52.92.163.9|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 140221178 (134M) [application/x-gzip]
Saving to: ‘boost_1_81_0.tar.gz’
boost_1_81_0.tar.gz 100%[====================================================================>] 133.72M 1.71MB/s in 85s
2022-12-24 08:20:43 (1.58 MB/s) - ‘boost_1_81_0.tar.gz’ saved [140221178/140221178]
Extract the compressed file:
foc@ubuntu22:~$ tar xvf boost_1_81_0.tar.gz
Enter the Boots directory:
foc@ubuntu22:~$ cd boost_1_81_0/
In this step, the source code will be built. So install the build dependencies:
foc@ubuntu22:~$ sudo apt install build-essential g++ python3-dev autotools-dev libicu-dev libbz2-dev-y
Give "bootstrap.sh" a "prefix" and run:
foc@ubuntu22:~/boost_1_81_0$ sudo ./bootstrap.sh --prefix=/usr/ Building B2 engine.. ### ### ### Using 'gcc' toolset. g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 Copyright (C) 2021 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. ### ###foc@ubuntu22:~/boost_1_81_0$ sudo ./bootstrap.sh --prefix=/usr/ > 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 Unicode/ICU support for Boost.Regex?... /usr Backing up existing B2 configuration in project-config.jam.1 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/
Then run b2:
foc@ubuntu22:~/boost_1_81_0$ ./b2
Performing configuration checks
- default address-model : 64-bit [1]
- default architecture : x86 [1]
Building the Boost C++ Libraries.
- compiler supports SSE2 : yes [2]
....
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/home/foc/boost_1_81_0
The following directory should be added to linker library paths:
/home/foc/boost_1_81_0/stage/lib
Then install with b2:
foc@ubuntu22:~/boost_1_81_0$ sudo ./b2 install
Performing configuration checks
- default address-model : 64-bit (cached) [1]
- default architecture : x86 (cached) [1]
- compiler supports SSE2 : yes (cached) [2]
...
common.copy /usr/lib/cmake/Boost-1.81.0/BoostConfig.cmake
common.copy /usr/lib/cmake/Boost-1.81.0/BoostConfigVersion.cmake
...updated 16003 targets...
After installation, the libraries are placed under the directory specified with "--prefix".
foc@ubuntu22:~$ ls /usr/lib/libboost_*
/usr/lib/libboost_atomic.a
/usr/lib/libboost_atomic.so
/usr/lib/libboost_atomic.so.1.81.0
/usr/lib/libboost_chrono.a
/usr/lib/libboost_chrono.so
/usr/lib/libboost_chrono.so.1.81.0
...
Boots installation completed successfully. You can use these libraries by adding them to your projects.
Summary
We installed the Boots libraries on Ubuntu with 2 different methods. We recommend installing from Ubuntu repositories. If you need to compile from source code for a different reason or need, the 2nd method will help for you.
References
stackoverflow.com - How to install Boost on Ubuntu
www.boost.org - Installation