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

相关推荐
运维Z叔1 小时前
云安全 | AWS S3存储桶安全设计缺陷分析
android·网络·网络协议·tcp/ip·安全·云计算·aws
Reese_Cool3 小时前
【C语言二级考试】循环结构设计
android·java·c语言·开发语言
平凡シンプル3 小时前
安卓 uniapp跨端开发
android·uni-app
elina80133 小时前
安卓实现导入Excel文件
android·excel
严文文-Chris3 小时前
【设计模式-享元】
android·java·设计模式
趋势大仙4 小时前
SQLiteDatabase insert or replace数据不生效
android·数据库
DS小龙哥4 小时前
QT For Android开发-打开PPT文件
android·qt·powerpoint
试行5 小时前
Android实现自定义下拉列表绑定数据
android·java
Dingdangr10 小时前
Android中的Intent的作用
android
技术无疆10 小时前
快速开发与维护:探索 AndroidAnnotations
android·java·android studio·android-studio·androidx·代码注入