Boost Arm 交叉编译

Boost Arm 交叉编译

1. 源码下载

下载地址:https://sourceforge.net/projects/boost/files/boost/
这里下载 1.74.0 版本
在这里插入图片描述
然后解压。

2. 配置

有些库我们是不需要的,所以就不需要编译,可以通过 -show-libraries 查看库列表

vincent@msi-creator-15:~/Temp/arm/boost_1_74_0$ 
---➤ ./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
    - nowide
    - program_options
    - python
    - random
    - regex
    - serialization
    - stacktrace
    - system
    - test
    - thread
    - timer
    - type_erasure
    - wave

通过 -without-libraries=, , , 逗号隔开去掉不想编译的库,并指定安装位置:

./bootstrap.sh --without-libraries=atomic,chrono --prifix=./install

这里还是全部编译了,所以直接执行下面命令

./bootstrap.sh --prefix=./install

执行后结果

vincent@msi-creator-15:~/Temp/arm/boost_1_74_0$ 
---➤ ./bootstrap.sh --prefix=./install
Building Boost.Build engine with toolset gcc... tools/build/src/engine/b2
Detecting Python version... 3.9
Detecting Python root... /home/vincent/anaconda3
Unicode/ICU support for Boost.Regex?... /usr
Generating Boost.Build configuration in project-config.jam for gcc...

Bootstrapping is done. To build, run:

    ./b2
    
To generate header files, run:

    ./b2 headers

To adjust configuration, edit 'project-config.jam'.
Further information:

   - Command line help:
     ./b2 --help
     
   - Getting started guide: 
     http://www.boost.org/more/getting_started/unix-variants.html
     
   - Boost.Build documentation:
     http://www.boost.org/build/

3. 修改配置

上一步将会生成主要的2个文件:

  1. b2
  2. project-config.jam

3.1 修改编译器

打开 project-config.jam 文件修改内的编译器
在这里插入图片描述
将此句修改为交叉编译器路径

using gcc : : /xxx/gcc-arm-11.2-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc ;

这里语法很苛刻,需要注意下面图内标注的地方都是需要有空格的。
在这里插入图片描述

3.2 修改安装目录

在这里插入图片描述
这里同样要注意空格。

3.3 其他配置

  1. 选项

    • build-type 构建类型,默认是 minimal ,此外还有 complete 选项。minimal 在Linux下只编译 release版本的多线程静态库和动态库。而 complete 在 unix/linux 下将会编译多个版本,即 debug 或 release,多线程或单线程,静态库或动态库。一般不建议全部编译,费时还费空间,提倡按需编译。

    • build-dir 构建目录,不指定将会在源码目录构建。

    • layout 确定是否选择库名和头文件位置,以便Boost的多个版本或多个编译器可以在同一个系统上使用。有以下3个选项配置。

      • versioned 二进制文件的名称包含版本号、编译器名称和版本以及编码的构建属性。头文件将会安装在 HDRDIR 的子目录中,其名称包含boost的版本号。
      • tagged 二进制文件的名称包含编码的构建属性,但不包含编译器名称和版本或boost版本。如果使用同一个编译器构建多个boost,推荐使用。
      • system 二进制文件名称不包含boost版本号或编译器的名称和版本号,boost头文件直接安装到 HDRDIR 目录中。

      windows 默认是选择 versioned,unix默认选择system。当 build-type 为 complete时,variant=debug,release属性时,必须要确保 layout=versioned或tagged。

    • without 设置排除编译的库。

  2. 属性

    • variant = debug|release,编译库的模式,支持同时编译。

    • link = static|shared,编译静态库还是动态库。

    • runtime-link =static|shared,指创建的库是静态链接还是动态链接到C运行库(或C++标准库),这个属性需要依据 link 的类型,不同的编译器允许的链接策略不一样,比如在 GCC 下,在生成动态库(-link=shared)时,就不允许进行静态链接到C运行库(或C++标准库)

      这里重点强调一下,当link为static时,runtime-link可以是shared,boost本身依赖的C/C++底层库就是动态链接的,但是对于boost而言是静态链接,好比A程序依赖boost,A与boost是静态链接,但是boost与C/C++运行库是动态的。

    • threading = single|multi,创建多线程还是单线程的版本。

    属性是支持同时设置的,比如:

    variant=debug,release
    # 或
    variant=debug variant=release
    

配置的命令示例如下:

./b2 --layout=tagged
     -sHAVE_ICU=1
     variant=debug,release 
     link=static 
     runtime-link=shared 
     threading=multi

sHAVE_ICU=1 代表支持 Unicode/ICU。

4. 编译

执行下面命令开始编译

./b2

编译成功后如下提示:
在这里插入图片描述

5. 安装

编程完成的静态或动态库文件就在stage目录中。

vincent@msi-creator-15:~/Temp/arm/boost_1_74_0$ 
---➤ tree -L 1 stage
stage
└── lib

但是缺少头文件,执行下面的命令进行安装,头文件和库将会拷贝到源码目录下的 install 目录中。

./b2 install

在这里插入图片描述

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FlyWine

你的鼓励将是我创作的做大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值