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,关于这些特殊库的编译大家可以自行查找资料,我这边就不介绍了。

相关推荐
威哥爱编程4 分钟前
鸿蒙 NEXT开发中轻松实现人脸识别功能
harmonyos
用户80547073681213 分钟前
【鸿蒙开发教程】HarmonyOS 实现List 列表
harmonyos
绵绵细雨中的乡音1 小时前
网络基础知识
linux·网络
Peter·Pan爱编程1 小时前
Docker在Linux中安装与使用教程
linux·docker·eureka
kunge20132 小时前
Ubuntu22.04 安装virtualbox7.1
linux·virtualbox
清溪5492 小时前
DVWA中级
linux
Sadsvit3 小时前
源码编译安装LAMP架构并部署WordPress(CentOS 7)
linux·运维·服务器·架构·centos
xiaok3 小时前
为什么 lsof 显示多个 nginx 都在 “使用 443”?
linux
苦学编程的谢4 小时前
Linux
linux·运维·服务器
G_H_S_3_4 小时前
【网络运维】Linux 文本处理利器:sed 命令
linux·运维·网络·操作文本