Boost库的编译

11 篇文章 0 订阅
10 篇文章 0 订阅

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 ;

在我们执行完命令后,就会编程我们指定的信息

一个汽车电子小白,记录自己学习过程中的点点滴滴。关注我,了解更多,相互交流学习

在这里插入图片描述

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Boost是一个开源的C++集合,提供了许多功能强大的组件和工具,用于增强C++语言的功能和性能。Qt是一个跨平台的应用程序开发框架,而MinGW是一个在Windows平台上使用的GNU工具集。 要编译Boost并与Qt和MinGW一起使用,可以按照以下步骤进行操作: 1. 下载Boost:首先,你需要从Boost官方网站(https://www.boost.org/)下载Boost的源代码。选择适合你的操作系统和编译器的版本。 2. 解压Boost:将下载的Boost源代码解压到你选择的目录中。 3. 打开命令提示符:在Windows上,按下Win + R键,输入"cmd"并按下Enter键,打开命令提示符。 4. 进入Boost目录:使用cd命令进入你解压Boost源代码的目录。 5. 运行bootstrap.bat:在命令提示符中运行bootstrap.bat脚本文件,它将为你的系统配置编译环境。 6. 编译Boost:运行b2命令来编译Boost。你可以使用一些选项来指定编译器和其他参数。例如,如果你想使用MinGW编译器,可以运行以下命令: ``` b2 toolset=gcc ``` 7. 安装Boost编译完成后,运行b2 install命令来安装Boost。这将把编译好的文件复制到指定的目录中。 8. 配置Qt项目:在Qt项目中使用Boost时,你需要在项目文件(.pro文件)中添加相应的配置。例如,如果你想使用Boost的某个模块,可以在.pro文件中添加以下行: ``` LIBS += -lboost_module INCLUDEPATH += /path/to/boost ``` 以上是编译Boost并与Qt和MinGW一起使用的基本步骤。具体的配置和使用方法可能因你的项目需求和环境而有所不同。如果遇到问题,可以参考Boost官方文档或在相关社区寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值