gpt4 book ai didi

boost - 从 Linux 上的源代码构建 Boost

转载 作者:行者123 更新时间:2023-12-03 16:30:34 25 4
gpt4 key购买 nike

描述:

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

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 ? ...基本上将安装所有这些 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)
我基本上遵循了 instructions :
运行 ./bootstrap.sh从我下载的地方(即在 /opt/boost_18_0/bootstrap.sh 中)
然后 ./b2
在 b2 过程结束时,它显示:
(...)
...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

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

最佳答案

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



sudo apt-get install libboost-all-dev会安装任何东西 x.y.z您的发行版的 boost 库版本(Debian、Ubuntu ...?)
已打包为 libboost-all-dev在最新的软件包更新中
您已申请到您的系统。在我的 Ubuntu 18.04 系统上发生
现在是 1.65.1。构建和安装 tarball boost_1_68_0.tar.bz2
你下载的当然会给你 1.68.0 版本。

如果您的包管理器提供了 libboost-all-dev在版本 1.68.0
(或作为源下载的相同版本),然后构建和
从源 tarball 安装将为您的 boost 客户端项目提供
通过编译和链接与安装完全相同的 boost 资源 libboost-all-dev包裹。

但是安装那个包不会
在文件系统中创建与构建和安装相同的目录和文件
源 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 .

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

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,但没有安装它。你跑了
./bootstrap.sh

/opt/boost_1_68_0 ,当它完成时它告诉你(除其他外)
Bootstrapping is done. To build, run:

./b2

那么,正如你所说,你跑了 ./b2 .也就是说,要建。并且在构建时
完成后,您看到了您发布的输出。它告诉你你成功的 boost build
现在可以通过指定编译器搜索选项在客户端项目中使用 -I/opt/boost_1_68_0和链接器搜索选项 -L/opt/boost_1_68_0/stage/lib .你可以像这样使用 boost 库,
从构建目录 /opt/boost_1_68_0 ,无需安装它们。这将是你必须要做的
如果您在系统上没有 root 权限,请执行此操作。

但如果你再看 the instructions
你链接到,你会发现:

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

您还没有运行 ./b2 install , 如果您指定或默认安装 --prefix需要 root 权限才能写入 - 默认情况下就是这种情况 /usr/local - 然后你需要运行
$ sudo ./b2 install

之后,您将在 /usr/local/include/boost 下看到 boost 头文件和库。
/usr/local/lib分别,并且您不需要指定任何显式 -I-L编译boost头文件或链接boost库的选项,因为 /usr/local/include是编译器的默认搜索路径, /usr/local/lib是默认搜索路径
链接器。

关于boost - 从 Linux 上的源代码构建 Boost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53647596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com