Boost库的编译
在ubuntu中,使用boost非常简单,直接使用apt安装就行,但是并不是所有的linux版本支持这种方式,这时,就需要使用boost的源码编译安装了,这里只说明arm架构下的交叉编译。
1、下载最新的boost源码文件: https://sourceforge.net/projects/boost/files/boost/
boost官网:www.boost.org
2、这里,使用的是1.71版本(注意,不同的版本,在不同的编译器下,可能会在install的步骤下报错,后面会解决办法)、
下载完成后,解压文件boost_1_71_0.tar.bz2
3、进入到boost_1_71_0后,可以使用命令查看boost下实现的库
./bootstrap.sh --show-libraries
Building Boost.Build engine with toolset gcc... tools/build/src/engine/b2
The following Boost libraries have portions that require a separate build
and installation step. Any library not listed here can be used by including
the headers only.
The Boost libraries requiring separate building and installation are:
- atomic
- chrono
- container
- context
- contract
- coroutine
- date_time
- exception
- fiber
- filesystem
- graph
- graph_parallel
- headers
- iostreams
- locale
- log
- math
- mpi
- program_options
- python
- random
- regex
- serialization
- stacktrace
- system
- test
- thread
- timer
- type_erasure
- wave
这里列出的是所有的库,但是我们可以只编译需要的库或者说不便宜哪些库,可以使用 ./bootstrap.sh --help 来查看支持哪些编译选择
`./bootstrap.sh' prepares Boost for building on a few kinds of systems.
Usage: ./bootstrap.sh [OPTION]...
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--with-bjam=BJAM use existing Boost.Jam executable (bjam)
[automatically built]
--with-toolset=TOOLSET use specific Boost.Build toolset
[automatically detected]
--show-libraries show the set of libraries that require build
and installation steps (i.e., those libraries
that can be used with --with-libraries or
--without-libraries), then exit
--with-libraries=list build only a particular set of libraries,
describing using either a comma-separated list of
library names or "all"
[all]
--without-libraries=list build all libraries except the ones listed []
--with-icu enable Unicode/ICU support in Regex
[automatically detected]
--without-icu disable Unicode/ICU support in Regex
--with-icu=DIR specify the root of the ICU library installation
and enable Unicode/ICU support in Regex
[automatically detected]
--with-python=PYTHON specify the Python executable [python]
--with-python-root=DIR specify the root of the Python installation
[automatically detected]
--with-python-version=X.Y specify the Python version as X.Y
[automatically detected]
Installation directories:
--prefix=PREFIX install Boost into the given PREFIX
[/usr/local]
--exec-prefix=EPREFIX install Boost binaries into the given EPREFIX
[PREFIX]
More precise control over installation directories:
--libdir=DIR install libraries here [EPREFIX/lib]
--includedir=DIR install headers here [PREFIX/include]
4、编译
这里,编译boost的目的是为了vsomeip 的编译,这里只需要编译log,system,thread这几个库,其中–prefix指定boost的安装路径,
新建boost的安装目录 boost_1_71_0_install,这里,我们不安装在系统路径,需要自己指定
./bootstrap.sh --with-libraries=log,system,thread --prefix=../boost_1_71_0_install
命令执行完成后,在目录下生成project-config.jam文件,
打开文件 project-config.jam,修改 using gcc : arm : arm-linux-gnueabihf-gcc ; 指定编译工具
注意,每个关键字前后都需要空格,否则会报错
修改后完就可以编译,一次执行
./b2
./b2 install
当然,在执行./b2 install时,有些boost的版本会有如下的错误
解决办法如下:
打开文件tools/build/src/tools/common.jam,定位到文件得977行(如果不是,前后找找),屏蔽掉图中的代码后,再编译
编译后的文件结构
5、另外说明下:在打开文件 project-config.jam后,会有一些这样的选项
这些并不是指定编译器用的,而是设置boost的安装相关的目录,可以从执行./bootstrap.sh命令后看出,默认情况下:
option.set prefix : /usr/local ;
option.set exec-prefix : /usr/local ;
option.set libdir : /usr/local/lib ;
option.set includedir : /usr/local/include ;
在我们执行完命令后,就会编程我们指定的信息
一个汽车电子小白,记录自己学习过程中的点点滴滴。关注我,了解更多,相互交流学习