linux下编译鸿蒙版boost库

我在上一篇文章中介绍了curl和openssl的编译方式(linux下编译鸿蒙版curl、openssl-CSDN博客),这篇再介绍一下boost库的编译。

未经许可,请勿转载!

一.环境准备

1.鸿蒙NDK

下载安装方式可以参考上篇文章,完毕后NDK的路径为:/home/ubuntu/develop/ohos-sdk-5.0/linux

2.下载boost库

我们可以在 Boost Version History查找自己需要的版本下载,我这边下载的是2020年的版本1.75.0。

下载完毕后解压到开发目录:/home/ubuntu/thirdparty/boost_1_75_0

二.编译流程

1.生成boost编译工具

在boost目录下执行 bootstrap.sh ,编译完成后生成编译工具 b2 ,以及要用到的project-config.jam

2.修改工程编译配置

bash 复制代码
vim project-config.jam

将配置文件内容清空,替换成如下配置:

bash 复制代码
modules.poke : NO_BZIP2 : 1 ;
# 设置ndk的路径
OHOS_NDK = /home/ubuntu/develop/ohos-sdk-5.0/linux ;
# 设置编译参数
using clang : ohos5.0 :
    $(OHOS_NDK)/native/llvm/bin/clang++ :
    <archiver>$(OHOS_NDK)/native/llvm/bin/llvm-ar
    <ranlib>$(OHOS_NDK)/native/llvm/bin/llvm-ranlib
    <compileflags>--sysroot=$(OHOS_NDK)/native/sysroot
    <compileflags>--target=aarch64-linux-ohos
    <compileflags>-fdata-sections
    <compileflags>-ffunction-sections
    <compileflags>-funwind-tables
    <compileflags>-fstack-protector-strong
    <compileflags>-no-canonical-prefixes
    <compileflags>-fno-addrsig
    <compileflags>-Wa,--noexecstack
    <compileflags>-D__MUSL__ ;

project : default-build <toolset>clang-ohos5.0 ;

# List of --with-<library> and --without-<library> options.
# If left empty, all libraries will be built.
# Options specified on the command line completely override this variable.
# 这边可以配置需要编译哪些库,不编译哪些库,我这边注释掉之后,就会编译所有库
#libraries = --with-filesystem --with-thread --with-system --with-regex --with-program_options --with-timer --with-chrono --with-iostreams --with-exception ;

这块配置是编译成功与否的关键,大家也可以自行增删需要的编译选项

3.修改 context 库编译配置

bash 复制代码
vim libs/context/build/Jamfile.v2

添加新的配置内容:

html 复制代码
alias asm_sources
   : asm/make_arm64_aapcs_elf_gas.S
     asm/jump_arm64_aapcs_elf_gas.S
     asm/ontop_arm64_aapcs_elf_gas.S
   : <abi>sysv
     <address-model>64
     <architecture>arm
     <binary-format>elf
     <toolset>clang-ohos
   ;

位置如图所示:

这边需要注意下,如果不修改该配置的话,在编译时会报 error: No best alternative for libs/context/build/asm_sources的错误。

另外还有一种方式可以解决这个错误,在不修改配置的情况下,我们可以在 b2 的编译命令行中加入编译参数 abi=aapcs

bash 复制代码
./b2 abi=aapcs ...

4.编译

bash 复制代码
./b2 -a --layout=versioned threadapi=pthread link=static threading=multi target-os=linux runtime-link=static stage --stagedir=ohos

我这边编译的是多线程静态库,大家可以根据需要自行调整编译参数,参数说明可以参考 ./b2 --help

三.编译结果

编译结束后,结果生成在 ohos/lib 下。其中有些库可能会编译失败,如 boost_python,关于这些特殊库的编译大家可以自行查找资料,我这边就不介绍了。

相关推荐
程序员小刘7 分钟前
【HarmonyOS 5】运动健康开发实践介绍以及详细案例
华为·harmonyos
御承扬14 分钟前
从零开始开发纯血鸿蒙应用之网络检测
网络·华为·harmonyos
搞Linux的杰仔19 分钟前
Ubuntu20.04基础配置安装——系统安装(一)
linux·嵌入式开发
Kaede63 小时前
如何应对Linux云服务器磁盘空间不足的情况
linux·运维·服务器
apocelipes8 小时前
Linux c 运行时获取动态库所在路径
linux·c语言·linux编程
努力学习的小廉9 小时前
深入了解linux系统—— 进程池
linux·运维·服务器
秃头菜狗9 小时前
各个主要目录的功能 / Linux 常见指令
linux·运维·服务器
2301_793102499 小时前
Linux——MySql数据库
linux·数据库
jiunian_cn11 小时前
【Linux】centos软件安装
linux·运维·centos
程序员JerrySUN11 小时前
[特殊字符] 深入理解 Linux 内核进程管理:架构、核心函数与调度机制
java·linux·架构