从Linux上的源构建Boost [英] Building Boost from sources on Linux

查看:67
本文介绍了从Linux上的源构建Boost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Ubuntu 18.04上的源代码构建Boost库(1.68).

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

1)对于同一版本,它等同于sudo apt-get install libboost-all-dev吗? ...基本上将安装所有这些部门:

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) 我基本上遵循了指令:
从我下载的位置(即在/opt/boost_18_0/bootstrap.sh中)运行./bootstrap.sh
然后./b2

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

在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

我想知道为什么根据--prefix选项的bootstrap.sh默认设置,它不应该位于/usr/local中?

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

推荐答案

1)它等同于sudo apt-get install libboost-all-dev

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

不. sudo apt-get install libboost-all-dev将安装任何内容 您发行版的Boost库的x.y.z版本(Debian,Ubuntu ...?) 在最新的软件包更新中已打包为libboost-all-dev 您已将其应用于系统.在我的Ubuntu 18.04系统上发生 现在是1.65.1.编译并安装tarball boost_1_68_0.tar.bz2 当然,您下载的版本将为1.68.0.

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.

如果您的程序包管理器在版本1.68.0中提供了libboost-all-dev (或与您下载的源代码相同的版本),然后构建并 从源代码tarball安装将为您的boost客户项目提供 通过编译和链接获得与安装完全相同的提升资源 libboost-all-dev程序包.

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.

但是安装该软件包不会 在文件系统中创建与构建和安装相同的目录和文件 源tarball,除非您使用./bootstrap.sh配置了相同的安装路径 (--prefix--includedir--libdir ...),如apt软件包安装所使用. 因此,例如我的apt安装libboost-all-dev安装了Boost /usr/include/boost下的标头和下的boost库二进制文件 /usr/lib/x86_64-linux-gnu.但是默认情况下,源tarball安装 将标头放在/usr/local/include/boost和库二进制文件下 在/usr/local/lib下.

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.

对于给定的boost版本,两者之间的唯一区别是 apt install libboost-all-dev和源版本,并使用默认安装进行安装 前缀(/usr/local)是在源代码构建和安装后,如果您希望链接和 使用boost shared (不是静态)库运行程序,则需要运行 $ sudo ldconfig(在任何目录中)以更新OS加载程序的动态链接缓存. apt install libboost-all-dev将自动更新ldconfig缓存.

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.

我想知道为什么根据--prefix选项的bootstrap.sh默认设置,它为什么不在/usr/local中?

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

那是因为您刚刚构建 Boost,但尚未安装.你跑了

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

./bootstrap.sh

/opt/boost_1_68_0中,当它完成时告诉您(还有其他事情)

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

Bootstrapping is done. To build, run:

    ./b2

因此,正如您所说的,您运行了./b2.也就是说,要构建.而当建筑 完成后,您看到了已发布的输出.它告诉您成功的提升构建 现在可以通过指定编译器搜索选项-I/opt/boost_1_68_0在客户端项目中使用 和链接程序搜索选项-L/opt/boost_1_68_0/stage/lib.您可以像这样使用boost库, 从构建目录 /opt/boost_1_68_0而不安装它们.这就是你必须要做的 如果您在系统上没有root权限,该怎么办.

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易于构建和安装

5.1 Easy Build and Install

在shell中发出以下命令(不要键入$;表示shell的提示符):

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

选择配置选项,然后不带--help选项再次调用./bootstrap.sh.除非您在系统的/usr/local/目录中具有写权限,否则您可能至少要使用

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

安装在其他地方.另外,考虑使用--show-libraries和--with-libraries = library-name-list选项来限制构建所有内容时的漫长等待.最后,

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

您尚未运行./b2 install,并且如果您指定了安装或默认安装 --prefix需要root权限才能写-默认/usr/local就是这种情况-然后您需要运行

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

在那之后,您将在/usr/local/include/boost下看到boost头文件和库 和/usr/local/lib,则无需指定任何显式的-I-L选项来编译boost头文件或链接boost库,因为/usr/local/include 是编译器的默认搜索路径,而/usr/local/lib是编译器的默认搜索路径. 链接器.

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.

这篇关于从Linux上的源构建Boost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆