boost库安装及其交叉编译

boost库安装及其交叉编译库生成



前言

本文介绍boost安装及不同平台架构运行的boost库编译。


一、boost是什么?

boost库是一个功能强大,构造精巧,跨平台的免费的C++开源库。它使得C++编程更优雅、更有活力、更高产,C++11的标准有三分之二来自boost库。在boost1.57版本时,就一共包含了129个组件,分为25个大类,涵盖了文本处理,容器,迭代器,算法,图像处理,模板元编程,并发编程等许多领域。

二、安装编译步骤

1.下载库

boost官网下载对应版本并解压,本文以boost_1.81.0为例:
官方安装参考

2.Install Boost.Build

安装b2

cd boost_1_81_0
cd tools/build
./bootstrap.sh
./b2 install prefix=../../b2_install

.bashrc或.zshrc中添加环境变量,Add b2_install/bin to your PATH environment variable

export PATH=/home/mini/data3/boost_1_81_0/b2_install/bin:$PATH

3.配置交叉编译环境,编辑user-config.jam如下

返回boost_1_81_0目录。
using gcc指定编译工具,设定不同交叉编译工具链即可编译相应目标板运行boost库。更多交叉编译官方参考B2 User Manual

using gcc : 4.9 : g++-4.9 : ; # 编译Ubuntu Trusty下运行库,前提是PC上已安装gcc4.9
using gcc : 7 : g++-7 : ; # 编译Ubuntu Bionic下运行库,前提是PC上已安装gcc7
using gcc : 9 : g++-9 : ; # 编译Ubuntu Focal下运行库,前提是PC上已安装gcc9
using gcc : tda4 : /home/mini/data3/lane_repo/tda4_rtos_sdk/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-g++ : ; # 编译armv8架构,Linux系统运行库
using gcc : mdc : /usr/local/mdc_sdk/dp_gea/mdc_cross_compiler/bin/aarch64-target-linux-gnu-g++ : ; # 编译armv8架构,Linux系统运行库
using gcc : cv22 : /home/mini/data3/amba/c1-sw-sdk/usr/bin/aarch64-linux-gnu-g++ : ; # 编译armv8架构,Linux系统运行库
using gcc : j3 : /home/mini/data3/j3_release/sdk_app/gcc-linaro-6.5.0-2018.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ : ; # 编译armv8架构,Linux系统运行库

4.写个简单的编译脚本方便编译以上各平台环境的boost运行库,编辑mk_conan_release.sh如下:

#!/bin/bash

RED_COLOR='\E[1;31m'   #红
GREEN_COLOR='\E[1;32m' #绿
YELOW_COLOR='\E[1;33m' #黄
BLUE_COLOR='\E[1;34m'  #蓝
RES='\E[0m'

platform=$1
cur_path=`pwd`
#echo ${cur_path}
arr=(${cur_path })
#echo ${arr[@]}
Repo_module=${arr[-1]}

echo -e "${RED_COLOR}<================== platform = ${platform} =====================>${RES}"
echo -e "${GREEN_COLOR}<================== module name = $Repo_module =====================>${RES}"

gcc_path=""

prj_path=/home/mini/data3

install_dir=${prj_path}/conan_dnp/pack_from_prebuild
install_prefix=${install_dir}/${Repo_module}/binaries/${platform}
echo -e "${BLUE_COLOR}<================== install_prefix = ${install_prefix} =====================>${RES}"

# 配置gcc
if [ $platform = "linux" ]; then
    b2 -j8 toolset=gcc-4.9 --user-config=./user-config.jam --build-dir=${platform}_build --prefix=${install_prefix} install
elif [ $platform = "linux_focal" ]; then
    b2 -j8 toolset=gcc-9 --user-config=./user-config.jam --build-dir=${platform}_build --prefix=${install_prefix} install
elif [ $platform = "cv22" ]; then
    b2 -j8 toolset=gcc-cv22 --user-config=./user-config.jam --build-dir=${platform}_build --prefix=${install_prefix} address-model=64 architecture=arm target-os=linux abi=aapcs install
elif [ $platform = "tda4" ]; then
    b2 -j8 toolset=gcc-tda4 --user-config=./user-config.jam --build-dir=${platform}_build --prefix=${install_prefix} address-model=64 architecture=arm target-os=linux abi=aapcs install
elif [ $platform = "mdc" ]; then
    b2 -j8 toolset=gcc-mdc --user-config=./user-config.jam --build-dir=${platform}_build --prefix=${install_prefix} address-model=64 architecture=arm target-os=linux abi=aapcs install
elif [ $platform = "j3" ]; then
    b2 -j8 toolset=gcc-j3 --user-config=./user-config.jam --build-dir=${platform}_build --prefix=${install_prefix} address-model=64 architecture=arm target-os=linux abi=aapcs install
else
    echo "Error : Unsupport Platform :"${platform}
    exit 0
fi

5.编译示例

./mk_conan_release.sh linux
./mk_conan_release.sh linux_focal
./mk_conan_release.sh cv22
./mk_conan_release.sh tda4
./mk_conan_release.sh mdc

总结

以上就是最近boost交叉编译工作的总结。鉴于网上各种文章,均未找到完全详尽指导交叉编译过程,特此记录,也希望给诸君有益参考。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
NDK交叉编译Boost是将Boost编译成适用于Android平台的文件,以便在Android应用中使用Boost的功能。下面是一般的NDK交叉编译Boost的步骤: 1. 下载NDK:首先,你需要下载并安装Android NDK,可以从官方网站(https://developer.android.com/ndk/downloads)上获取最新版本的NDK。 2. 下载Boost:接下来,你需要下载Boost的源代码。你可以从Boost官方网站(https://www.boost.org/users/download/)上下载最新版本的Boost。 3. 配置Boost:解压下载的Boost源代码,并进入解压后的目录。在终端中执行以下命令来配置Boost: ``` ./bootstrap.sh --with-libraries=<library_names> --with-toolset=<toolset_name> --prefix=<install_path> ``` 其中,`<library_names>`是你需要编译的Boost的名称,可以根据你的需求进行选择;`<toolset_name>`是你要使用的编译工具链,例如`clang`或`gcc`;`<install_path>`是你希望安装Boost的路径。 4. 编辑user-config.jam文件:在Boost源代码目录下,创建一个名为`user-config.jam`的文件,并添加以下内容: ``` using clang : <ndk_version> : <path_to_ndk>/toolchains/llvm/prebuilt/<host_os>/bin/clang++ ; ``` 其中,`<ndk_version>`是你下载的NDK的版本号,`<path_to_ndk>`是你安装NDK的路径,`<host_os>`是你的操作系统类型(例如`darwin-x86_64`或`linux-x86_64`)。 5. 开始编译Boost:在终端中执行以下命令来开始编译Boost: ``` ./b2 toolset=clang-<ndk_version> target-os=android link=static threading=multi variant=release install ``` 这将使用指定的编译工具链和选项来编译Boost,并将编译结果安装到之前配置的安装路径中。 6. 完成编译:等待编译过程完成,然后你将在之前配置的安装路径中找到编译好的Boost文件。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值