Installation and use of cpp boost library based on ubuntu and windows, including Jupiter notebook / Lab exus clicking kernel and vs code to add a third-party library

reference material

All references are from the boost official website https://www.boost.org/

Introduction to boost library

Too lazy to write

Installation of boost library

ubuntu based on linux

Official guide
https://www.boost.org/doc/libs/1_78_0/more/getting_started/unix-variants.html
The writing is vague

Download and unzip

https://boostorg.jfrog.io/artifactory/main/release/1.78.0/source/
Choose a version to download at will on this page

For example, I downloaded: boost_1_78_0.tar.gz
Open Terminal and enter the downloaded folder. Instructions:

tar -xzvf boost_1_78_0.tar.gz #boost_1_78_0.tar.gz is the file name

In fact, it is decompression. What you don't understand here needs to learn the tar method
Detailed explanation of tar instruction

Preconditions

You need to have at least one compilation environment before you start installing the boost library

If there is no compilation environment, running directly will display
Could not find a suitable toolset.

You can specify the toolset as the argument, i.e.:
    ./build.sh [options] gcc

Toolsets supported by this script are:
    acc, clang, como, gcc, intel-darwin, intel-linux, kcc, kylix, mipspro,
    pathscale, pgi, qcc, sun, sunpro, tru64cxx, vacpp

Almost
If prompted, you can run the command:

sudo apt install build-essential

Build essential contains basic compilers such as gcc g + +, which are packaged by ubuntu. Of course, you can also install clang or gcc yourself

Formal installation phase 1

Open terminal, enter the extracted folder, and execute:

sudo ./bootstrap.sh

Successful operation will be displayed as follows

Building B2 engine..

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

g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 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
> cp b2 bjam
tools/build/src/engine/b2
Unicode/ICU support for Boost.Regex?... not found.
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/

Before the next installation,

Enter root permission

Most of the time, you need to enter the root permission first, otherwise the next installation will fail

su root#Enter root permission

Then enter the password. If su: Authentication failure is displayed all the time, it may be because the root password is not set. You need to

sudo passwd root#Set root password

Enter root successfully and proceed to the next step

Formal installation phase 2

./b2 install

It will be installed to / usr/local by default and can also be used/ b2 install --prefix = to set the installation location. See for many other operations/ b2 --help

installation is complete

windows

Download and unzip

https://boostorg.jfrog.io/artifactory/main/release/1.78.0/source/
Download boost_ 1_ 78_ Unzip 0.zip to the location you want

install

Go to that folder and run bootstrap Bat generates B2 exe
Run B2 exe
installation is complete

Use of boost library

VS Code

c_cpp_properties.json

In c_cpp_properties.json file

            "includePath": [
                "${workspaceFolder}/**",
                "F:\\Library\\boost_1_78_0\\**"
            ],
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "F:\\Library\\boost_1_78_0\\**"
                ]
            },

Two of them are F:\Library\boost_1_78_0 \ \ replace it with the folder where you installed boost. This is under win. Change the slash under linux (in fact, it can be used directly / under win)

tasks.json

In tasks JSON file

            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.exe",
                "-g",
                "-I F:\\Library\\boost_1_78_0\\",
                "-Wall",
                "-static-libgcc",
                "-fexec-charset=UTF-8",
                "-std=c++17",
                "-lpthread",
                "-lboost_thread",
                "-lboost_system"
            ],

"- I F:\Library\boost_1_78_0 \ \" needs to be added,
-The address after I is the location where boost is installed

setttings.json

If code runner, etc. is used, it needs to be in settings Add "- I F:\Library\boost_1_78_0 \ \" to the args of JSON code runner, which is actually the same as in task JSON adds a meaning

jupyter notebook/lab exus-cling kernel

If you use jupyter notebook/lab and install the exus clicking kernel in the initial cell, or write one yourself h when used later #include

#pragma cling add_ library_ Path ("folder address of library file") / / Add library path 
#pragma cling add_ include_ Path ("folder address of include header file, etc.) / / include path
#Pragma click load ("address of external shared library") / / Add an external shared library 

You can normally #include it later

Keywords: Windows jupyter Ubuntu Visual Studio Code

Added by gojiita on Tue, 04 Jan 2022 22:16:19 +0200