Boost is a widely used collection of C++ libraries that provides many powerful and flexible components to help developers write C++ code more efficiently. Please click the link Boost official website to enter the Boost official website and select the corresponding version of the compressed package to download. Here the author chose the boost_1_82_0 version, which provides a direct download link boost_1_82_0.tar.gz . Right-click the mouse to copy the link and enter the following code in the Linux terminal. Can
wget https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.tar.gz
1. Unzip in the corresponding directory
tar -xvzf boost_1_82_0.tar.gz
2. Unzip and enter the corresponding directory
cd boost_1_82_0
3. Run the bootstrap.sh file in the source directory
./bootstrap.sh
4. After the operation is completed, the b2 executable file will be generated in the source code directory, just run it.
ps: If an error is reported here./b2: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./b2) ./b2: /lib64/libstdc++.so.6: version `GLIBCXX_3. 4.21' not found (required by ./b2) You can read the author’s other article to solve the problem of missing libstdc++ standard version library
./b2 -j`nproc`
5. After running, run the following command:
./b2 install -j`nproc`
6. Verify installation
Create a new file main.cpp anywhere
vi main.cpp
#include <iostream>
#include <boost/version.hpp>
int main() {
std::cout << "Boost version: " << BOOST_LIB_VERSION << std::endl;
return 0;
}
After exiting and saving, enter the following command to compile and execute:
g++ -o main main.cpp -lboost_system
./main
Get the output of the boost version number, as follows:
This means the installation is successful.