Windows下编译使用NDK编译Boost库

1 篇文章 0 订阅
1 篇文章 0 订阅

背景

安卓开发中需要使用线程库

准备工作

  1. 下载ndk10e:地址
  2. 下载boost库:boost_1_69_0.zip
  3. 将“android-ndk-r10e-windows-x86.zip”和“boost_1_69_0.zip”解压到G盘根目录,得:“G:\boost_1_69_0\”和"G:\android-ndk-r10e"

成功编译的步骤

  1. 运行"G:\boost_1_69_0\bootstrap.bat"
  2. 替换"G:\boost_1_69_0\project-config.jam"文件的内容,可复制下文:
# define platform name of ndk
import os ;
if [ os.name ] = CYGWIN || [ os.name ] = NT
{
    androidPlatform = windows ;
}
else if [ os.name ] = LINUX
{
    androidPlatform = linux-x86_64 ;
}
else if [ os.name ] = MACOSX
{
    androidPlatform = darwin-x86 ;
}

# replace with your own path
ANDROID_NDK = "G:/android-ndk-r10e" ;

# compile with gcc, you can change compiler to clang or others
using gcc : 4.9 : $(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.9/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-g++ :
<archiver>$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.9/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ar
<ranlib>$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.9/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ranlib
<compileflags>-I$(ANDROID_NDK)/platforms/android-19/arch-arm/usr/include
<compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.9/include
<compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.9/include/backward
<compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-fpic
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-D__ARM_ARCH_5__
<compileflags>-D__ARM_ARCH_5T__
<compileflags>-D__ARM_ARCH_5E__
<compileflags>-D__ARM_ARCH_5TE__
<compileflags>-D__ARM_ARCH_7__
<compileflags>-D__ARM_ARCH_7A__
<compileflags>-Wno-psabi
<compileflags>-march=armv7-a
<compileflags>-mtune=xscale
<compileflags>-mfloat-abi=softfp
<compileflags>-marm
<compileflags>-mthumb
<compileflags>-Os
<compileflags>-std=gnu++11
<compileflags>-fomit-frame-pointer
<compileflags>-fno-strict-aliasing
<compileflags>-finline-limit=64
<compileflags>-Wa,--noexecstack
<compileflags>-DANDROID
<compileflags>-D__ANDROID__
<compileflags>-D__ARM_EABI__
<compileflags>-DNDEBUG
<compileflags>-O2
<compileflags>-g
;

# project default compiler
project : default-build <toolset>gcc-4.9 ;

# replace with libraries you wanna to build
#libraries = --with-container --with-coroutine --with-fiber --with-graph --with-graph_parallel --with-log --with-python --with-test --with-type_erasure --with-atomic --with-date_time --with-program_options --with-chrono --with-context --with-iostreams --with-locale --with-mpi --with-serialization  --with-timer --with-wave --with-math --with-random --with-exception --with-filesystem --with-thread --with-system --with-regex --with-program_options ;

libraries = --with-thread ;
  1. 打开cmd窗口,切换当前目录到"G:\boost_1_69_0",执行命令
.\b2.exe link=static runtime-link=static target-os=linux --stagedir=android

遇到的问题

找不到g++

报错的部分内容如下:

G:/boost_1_69_0/tools/build/src/tools\gcc.jam:164: in gcc.init from module gcc
error: toolset gcc initialization:
error: provided command 'G:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.
9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++' not found
error: initialized from project-config.jam:56

核对文件的路径发现,其真实的路径应该为"G:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.
9/prebuilt/windows/bin/arm-linux-androideabi-g++",观察“project-config.jam”发现,路径中的只有“windows”没有“-x86_64”,所以需要删除。如下图所示~~~~

参数错误

报错的部分内容如下:

Performing configuration checks

    - default address-model    : 32-bit
    - default architecture     : arm

Building the Boost C++ Libraries.


    - lockfree boost::atomic_flag : no
G:/boost_1_69_0/tools/build/src/tools\common.jam:973: in toolset-tag
*** argument error
* rule numbers.less ( n1 n2 )
* called with: ( 4 )
* missing argument n2
G:/boost_1_69_0/tools/build/src/util\numbers.jam:66:see definition of rule 'numb
ers.less' being called~~~~

根据提示,查看文件“G:/boost_1_69_0/tools/build/src/tools\common.jam”的第973行,如下图所示:猜测与gcc的版本有关系,而从参考文档1中复制的配置文件中有关于gcc的内容只有如图所示的部分:,统合错误提示,猜测与前面的android有关,删除后再次尝试,编译成功

延伸思考

  1. 配置文件中已经指定了默认的toolset,所以不用在命令行中再次指定了,同理,需要编译的library也在配置文件中指定了,也不需要在命令行中再次指定,故,相比与参考文档,第3步的命令更短、更方便。猜测可以全部放到配置文件中,命令仅.\b2.exe,应该也行~~~~

参考文档

  1. Windows下NDK直接编译编译boost 1.55(X86版本)
  2. ubuntu16.04编译boost for Android
  3. boost_for_android
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值