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库。

相关推荐
duwei_wang2 小时前
[Android]-Admob配置过多导致的慢消息
android
雨白3 小时前
发送自定义广播
android
雨白4 小时前
深入理解广播机制 (BroadcastReceiver)
android
婵鸣空啼8 小时前
GD图像处理与SESSiON
android
sunly_8 小时前
Flutter:导航固定背景图,滚动时导航颜色渐变
android·javascript·flutter
用户2018792831679 小时前
简单了解android.permission.MEDIA_CONTENT_CONTROL权限
android
_一条咸鱼_9 小时前
Android Runtime类卸载条件与资源回收策略(29)
android·面试·android jetpack
顾林海9 小时前
Android Bitmap治理全解析:从加载优化到泄漏防控的全生命周期管理
android·面试·性能优化
砖厂小工9 小时前
Now In Android 精讲 8 - Gradle build-logic 现代构建逻辑组织方式
android
玲小珑9 小时前
Auto.js 入门指南(八)高级控件与 UI 自动化
android·前端