ndk-r20b 编译 boost 1.74。

ndk-r20b 编译 boost 1.74,这是 ndk-r20b 支持得最大 boost 版本,再大就没法编译支持了,本文介绍方法是完整编译,不需要完整编译请转移到github,boost for android 得开源项目。

1.74 boost ,安卓上面得版本编译,我这边编译了两个版本,不想编译就自己 clone 仓库。

-fPIE 编译(编程序用)

liulilittle/boost-1.74-for-android-r20b: The maximum available static libraries on the Android platform are compiled using the Android NDK r20b toolchain + Android API 23, including libboost_context.a and libboost_coroutine.a. (github.com)

-fPIC 编译(动态库用)

liulilittle/boost-1.74-for-android-r20b-fpic: The maximum available static libraries on the Android platform are compiled using the Android NDK r20b toolchain + Android API 23, including libboost_context.a and libboost_coroutine.a. (github.com)

先安装NDK-R20B,解压目录假定为:

/root/android/ndk/r20b

所以ANDROID_API_21版本得编译为:

/root/android/ndk/r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android21-clang++

/root/android/ndk/r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang++

/root/android/ndk/r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++

/root/android/ndk/r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang++

人们必须看本人这篇文章:

Ubuntu 18.04 x86_64 上交叉编译 boost 库(ARMv7L)_armv7l 交叉编译环境-CSDN博客

1、下载 boost 1.84 的源代码访问要编译的目录,并且解压出来源代码,切入源代码根目录

2、./bootstrap.sh --with-toolset=clang

3、上一条命令生成出 b2,之后同时还会生成一个 project-config.jam 的配置文件

4、修改这个配置文件

把这段

cpp 复制代码
if ! gcc in [ feature.values <toolset> ]
{
    using clang ;
}

替换成

cpp 复制代码
if ! gcc in [ feature.values <toolset> ]
{
    using clang : x86 : /root/android/ndk/r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang++ ; 
}

x86 可以直接编译出来,32位、64位,就是 amd64、intel386/intel686 机可以直接编译支持,就是 arm 得需要修改下。

在这个 nano libs/context/build/Jamfile.v2 文件之中增加架构(编译补丁):

bash 复制代码
alias asm_sources
   : asm/make_arm_aapcs_elf_gas.S
     asm/jump_arm_aapcs_elf_gas.S
     asm/ontop_arm_aapcs_elf_gas.S
   : <abi>sysv
     <address-model>32
     <architecture>arm
     <binary-format>elf
     <toolset>clang
   ;
 
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
   ;

最后编译 boost 库:

./b2 cxxflags=-fPIC

确定 boost context 库是否正确的被编译,不正确编译也是会生产库(so、a)文件的,所以要自己去输出库搜下导出符号信息:

cd stage/lib

strings libboost_context.a | grep make_fcontext

objdump -D -tT -C libboost_context.a | grep make_fcontext

nm -C libboost_context.a | grep make_fcontext

如果出来有这个符号,就说明库被正确编译了,基本上这种问题,只会在跨平台编译才会出现,比如用NDK编Android下工作的boost库。

相关推荐
小袁拒绝摆烂2 小时前
SQL开窗函数
android·sql·性能优化
apihz3 小时前
VM虚拟机全版本网盘+免费本地网络穿透端口映射实时同步动态家庭IP教程
android·服务器·开发语言·网络·数据库·网络协议·tcp/ip
baidu_247438613 小时前
Android MPAndroidChart使用
android
天平4 小时前
react native现代化组件库的推荐 【持续更新...】
android·前端·react native
apihz5 小时前
通用图片搜索-搜狗源免费API接口使用指南
android·java·python·php·音视频
你过来啊你6 小时前
Android开发中ARouter使用和原理详解
android
apihz7 小时前
腾讯云轻量服务器创建快照免费API接口教程
android·服务器·数据库·python·网络协议·tcp/ip·腾讯云
Kiri霧8 小时前
Noting
android·开发语言·kotlin
东风西巷13 小时前
NealFun安卓版:创意无限,娱乐至上
android·人工智能·智能手机·娱乐·软件需求
小李飞飞砖19 小时前
Sophix、Tinker 和 Robust 三大主流 Android 热修复框架的详细对比
android