牛商网专注营销型网站建设,最专业的医疗网站建设,如何做网站seo排名优化,wordpress如何多用户我在上一篇文章中介绍了curl和openssl的编译方式#xff08;linux下编译鸿蒙版curl、openssl-CSDN博客#xff09;#xff0c;这篇再介绍一下boost库的编译。
未经许可#xff0c;请勿转载#xff01;
一.环境准备
1.鸿蒙NDK
下载安装方式可以参考上篇文章#xff0c…我在上一篇文章中介绍了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.修改工程编译配置
vim project-config.jam
将配置文件内容清空替换成如下配置
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-arranlib$(OHOS_NDK)/native/llvm/bin/llvm-ranlibcompileflags--sysroot$(OHOS_NDK)/native/sysrootcompileflags--targetaarch64-linux-ohoscompileflags-fdata-sectionscompileflags-ffunction-sectionscompileflags-funwind-tablescompileflags-fstack-protector-strongcompileflags-no-canonical-prefixescompileflags-fno-addrsigcompileflags-Wa,--noexecstackcompileflags-D__MUSL__ ;project : default-build toolsetclang-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 库编译配置
vim libs/context/build/Jamfile.v2
添加新的配置内容
alias asm_sources: asm/make_arm64_aapcs_elf_gas.Sasm/jump_arm64_aapcs_elf_gas.Sasm/ontop_arm64_aapcs_elf_gas.S: abisysvaddress-model64architecturearmbinary-formatelftoolsetclang-ohos;
位置如图所示 这边需要注意下如果不修改该配置的话在编译时会报 error: No best alternative for libs/context/build/asm_sources 的错误。
另外还有一种方式可以解决这个错误在不修改配置的情况下我们可以在 b2 的编译命令行中加入编译参数 abiaapcs
./b2 abiaapcs ...
4.编译
./b2 -a --layoutversioned threadapipthread linkstatic threadingmulti target-oslinux runtime-linkstatic stage --stagedirohos
我这边编译的是多线程静态库大家可以根据需要自行调整编译参数参数说明可以参考 ./b2 --help
三.编译结果
编译结束后结果生成在 ohos/lib 下。其中有些库可能会编译失败如 boost_python关于这些特殊库的编译大家可以自行查找资料我这边就不介绍了。