Boost Compiler Installation under Linux

Boost library is a portable C++ library that provides source code. As a backup of standard library, it is one of the development engines of C++ standardization process. The Boost library is sponsored by members of the working group of the C++ Standards Committee Library. Some of its contents are expected to become the next generation of C++ Standards Library. It has a great influence in the C++ community and is a "quasi" standard library. Boost's emphasis on cross-platform and standard C++ has nothing to do with the writing platform. Most boost libraries only need to include header files, while a few (such as regular expression libraries, file system libraries, etc.) need link libraries.

Installation steps:

wget https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.gz
tar zxvf boost_1_64_0.tar.gz
cd boost_1_64_0.tar.gz
./bootstrap.sh --with-libraries=all --with-toolset=gcc ##with-libraries specifies which boost libraries to compile, all of which is to compile. If you only want to compile some libraries, you can write the names of libraries, separated by numbers, and the libraries you can specify are described below. With-tool specifies which compiler to use at compilation time, and GCC can be used under Linux. If multiple versions of GCC are installed in the system, you can specify the version of GCC here, such as -- with-tool set = gcc-4.4.

When the command is executed, it is successful to see as follows:

Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 2.6
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...

Bootstrapping is done. To build, run:

    ./b2

To adjust configuration, edit 'project-config.jam'.
Further information:

   - Command line help:
     ./b2 --help

   - Getting started guide: 
     http://www.boost.org/more/getting_started/unix-variants.html

   - Boost.Build documentation:
     http://www.boost.org/build/doc/html/index.html

Compile

./b2 toolset=gcc

Install boost

./b2 install --prefix=/usr  ##--prefix=/usr Used to specify boost The default header file without this parameter is/usr/local/include/boost Under the directory, the library files are in/usr/local/lib/Under the catalogue. Here the installation directory is specified as--prefix=/usr be boost It will be installed directly into the system header file directory and library file directory, and the configuration environment variables can be omitted.

Finally, if you want to compile with the boost library immediately after installation, you need to execute this command:

ldconfig

The designated libraries are:
Description of Library Name
atomic
chrono
context
coroutine
date_time
exception
filesystem
graph Components and Algorithms
graph_parallel
iostreams
locale
log
math
Metaprogramming Framework Implemented by Template in mpi
program_options
Python maps C++ classes and functions to Python
random
regex regular expression library
serialization
signals
system
test
thread Portable C++ Multithread Library
timer
wave

Boost usage testing
Take boost_thread as an example to test whether the newly installed boost library can be used correctly. The test code is as follows:

#include <boost/thread/thread.hpp> //Contains boost header files
#include <iostream>
#include <cstdlib>
using namespace std;

volatile bool isRuning = true;

void func1()
{
    static int cnt1 = 0;
    while(isRuning)
    {
        cout << "func1:" << cnt1++ << endl;
        sleep(1);
    }
}

void func2()
{
    static int cnt2 = 0;
    while(isRuning)
    {
        cout << "\tfunc2:" << cnt2++ << endl;
        sleep(2);
    }
}

int main()
{
    boost::thread thread1(&func1);
    boost::thread thread2(&func2);

    system("read");
    isRuning = false;

    thread2.join();
    thread1.join();
    cout << "exit" << endl;
    return 0;
}

Compiler:

g++ main.cpp -g -o main -lboost_thread

If the boost library is not installed in the system directory, you also need to specify the location of boost header files and library files by adding - I and - L at compile time.

After compiling the program successfully, the multithreaded tasks implemented by boost run correctly:

When compiling, if you encounter the error shown in the figure:

Implementation:

LD_LIBRARY_PATH=/usr/local/lib64/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

Then recompile and run.

Keywords: Python Linux Unix

Added by mimilaw123 on Fri, 21 Jun 2019 01:32:07 +0300