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

相关推荐
黑牛先生18 分钟前
【Linux】动静态库
linux·运维·服务器
vortex519 分钟前
Shell基础:中括号的使用
linux·运维·bash·shell
ChinaDragonDreamer3 小时前
HarmonyOS:MVVM模式
harmonyos·鸿蒙
-VE-4 小时前
myshell
linux·c++
身在江湖的郭大侠6 小时前
Linux内核
linux·服务器
RZer8 小时前
HarmonyOS应用开发快速入门
华为·harmonyos
破-风8 小时前
linux的用法
linux·运维·服务器
涛ing12 小时前
32. C 语言 安全函数( _s 尾缀)
linux·c语言·c++·vscode·算法·安全·vim
__雨夜星辰__12 小时前
Linux 学习笔记__Day2
linux·服务器·笔记·学习·centos 7
大耳朵土土垚12 小时前
【Linux】日志设计模式与实现
linux·运维·设计模式