Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building Boost from sources on Linux

Tags:

build

boost

Description:

I am trying to build the Boost library (1.68) from sources on Ubuntu 18.04.

https://www.boost.org/doc/libs/1_68_0/more/getting_started/unix-variants.html
https://www.boost.org/users/history/version_1_68_0.html

Questions:

1) For a same version, is it equivalent to a sudo apt-get install libboost-all-dev? ...which basically will install all theses deps:

The following NEW packages will be installed:    
  libboost-all-dev libboost-atomic-dev libboost-atomic1.65-dev libboost-atomic1.65.1 libboost-chrono-dev libboost-chrono1.65-dev
  libboost-chrono1.65.1 libboost-container-dev libboost-container1.65-dev libboost-container1.65.1 libboost-context-dev
  libboost-context1.65-dev libboost-context1.65.1 libboost-coroutine-dev libboost-coroutine1.65-dev libboost-coroutine1.65.1
  libboost-date-time-dev libboost-date-time1.65-dev libboost-exception-dev libboost-exception1.65-dev libboost-fiber-dev
  libboost-fiber1.65-dev libboost-fiber1.65.1 libboost-filesystem-dev libboost-filesystem1.65-dev libboost-graph-dev
  libboost-graph-parallel-dev libboost-graph-parallel1.65-dev libboost-graph-parallel1.65.1 libboost-graph1.65-dev
  libboost-graph1.65.1 libboost-iostreams-dev libboost-iostreams1.65-dev libboost-locale-dev libboost-locale1.65-dev
  libboost-log-dev libboost-log1.65-dev libboost-log1.65.1 libboost-math-dev libboost-math1.65-dev libboost-math1.65.1
  libboost-mpi-dev libboost-mpi-python-dev libboost-mpi-python1.65-dev libboost-mpi-python1.65.1 libboost-mpi1.65-dev
  libboost-mpi1.65.1 libboost-numpy-dev libboost-numpy1.65-dev libboost-numpy1.65.1 libboost-program-options-dev
  libboost-program-options1.65-dev libboost-program-options1.65.1 libboost-python-dev libboost-python1.65-dev
  libboost-python1.65.1 libboost-random-dev libboost-random1.65-dev libboost-random1.65.1 libboost-regex-dev
  libboost-regex1.65-dev libboost-regex1.65.1 libboost-serialization-dev libboost-serialization1.65-dev
  libboost-serialization1.65.1 libboost-signals-dev libboost-signals1.65-dev libboost-signals1.65.1 libboost-stacktrace-dev
  libboost-stacktrace1.65-dev libboost-stacktrace1.65.1 libboost-system-dev libboost-system1.65-dev libboost-test-dev
  libboost-test1.65-dev libboost-test1.65.1 libboost-thread-dev libboost-thread1.65-dev libboost-timer-dev libboost-timer1.65-dev
  libboost-timer1.65.1 libboost-tools-dev libboost-type-erasure-dev libboost-type-erasure1.65-dev libboost-type-erasure1.65.1
  libboost-wave-dev libboost-wave1.65-dev libboost-wave1.65.1 libboost1.65-tools-dev

2) I basically followed the instructions:
running ./bootstrap.sh from where I downloaded (i.e. in /opt/boost_18_0/bootstrap.sh)
and then ./b2

at the end of the b2 process, it showed:

(...)
...updated 1275 targets...

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:
    /opt/boost_1_68_0

The following directory should be added to linker library paths:
    /opt/boost_1_68_0/stage/lib

I wonder why it's not located in /usr/local where it should according to the bootstrap.sh default setting for the --prefix option?

like image 429
s.k Avatar asked Dec 06 '18 08:12

s.k


People also ask

How do I build a Boost library?

Right-click example in the Solution Explorer pane and select Properties from the resulting pop-up menu. In Configuration Properties > Linker > Additional Library Directories, enter the path to the Boost binaries, e.g. C:\Program Files\boost\boost_1_62_0\lib\. From the Build menu, select Build Solution.


1 Answers

1) Is it equivalent to a sudo apt-get install libboost-all-dev

No. sudo apt-get install libboost-all-dev will install whatever x.y.z version of the boost libraries your distro (Debian, Ubuntu ...?) has packaged as libboost-all-dev in the latest package updates that you have applied to your system. On my Ubuntu 18.04 system that happens to be 1.65.1 right now. Building and installing the tarball boost_1_68_0.tar.bz2 that you downloaded will of course give you version 1.68.0.

If your package manager provides a libboost-all-dev at version 1.68.0 (or the same version that your download as source), then building and installing from the source tarball will provide your boost client projects with exactly the same boost resources via compilation and linkage as installing the libboost-all-dev package.

But installing that package will not create the same directories and files in your filesystem as building and installing the source tarball unless with ./bootstrap.sh you configure the same installation paths (--prefix, --includedir, --libdir...) as are used by the apt package installation. So, e.g. My apt installation of libboost-all-dev installs the boost headers under /usr/include/boost and the boost library binaries under /usr/lib/x86_64-linux-gnu. But by default the source tarball installation will place the headers under /usr/local/include/boost and the library binaries under /usr/local/lib.

For a given version of boost, the only other difference between apt install libboost-all-dev and a source build and install with the default install prefix (/usr/local) is that after a source build and install, if you wish to link and run your programs with the boost shared (not static) libraries, you will need to run $ sudo ldconfig (in any directory) to update the OS loader's dynamic linkage cache. apt install libboost-all-dev will update the ldconfig cache automatically.

I wonder why it's not located in /usr/local where it should according to the bootstrap.sh default setting for the --prefix option?

That is because you have just built boost, but not installed it. You ran

./bootstrap.sh

in /opt/boost_1_68_0, and when it finished it told you (amoung other things)

Bootstrapping is done. To build, run:

    ./b2

So then, as you say, you ran ./b2. That is, to build. And when building had finished, you saw the output you've posted. It tells you that your successful boost build can now be used in client projects by specifying the compiler search option -I/opt/boost_1_68_0 and the linker search option -L/opt/boost_1_68_0/stage/lib. You can your use boost libraries like that, from the build directory /opt/boost_1_68_0, without installing them. This would be what you'd have to do if you didn't have root privilege on your system.

But if you look again at the instructions you linked to, you'll find:

5.1 Easy Build and Install

Issue the following commands in the shell (don't type $; that represents the shell's prompt):

Select your configuration options and invoke ./bootstrap.sh again without the --help option. Unless you have write permission in your system's /usr/local/ directory, you'll probably want to at least use

$ ./bootstrap.sh --prefix=path/to/installation/prefix

to install somewhere else. Also, consider using the --show-libraries and --with-libraries=library-name-list options to limit the long wait you'll experience if you build everything. Finally,

$ ./b2 install

You haven't run ./b2 install, and if your specified or default installation --prefix requires root privilege to write - which is the case for the default /usr/local - then you need to run

$ sudo ./b2 install

After that, you'll see the boost headers and libraries under /usr/local/include/boost and /usr/local/lib respectively, and you will not need to specify any explicit -I or -L options to compile boost headers or link boost libraries, because /usr/local/include is a default search path for the compiler and /usr/local/lib is a default search path for the linker.

like image 157
Mike Kinghan Avatar answered Oct 12 '22 07:10

Mike Kinghan