在android ndk中使用Boost与windows

Using Boost in android ndk with windows

本文关键字:Boost windows android ndk      更新时间:2023-10-16

我正在尝试在Eclipse和Windows中使用Android ndk的boost库。我试着遵循这个教程

我被cygwin中的"bjam"命令卡住了。

bjam--没有python--没有序列化工具集=gcc-android4.4.3链接=静态运行时链接=静态目标os=linux--stagedir=android

错误:找不到bjam命令。

什么是bjam?此外,我使用了增强1.53沿着ndk r8e。有人能帮我做这个吗?

Android NDK不再依赖Cygwin,因此您可以在Windows命令提示符(cmd)中使用NDK构建Boost。

为了使Boost.Build找到NDK,编辑boosttoolsbuildv2user-config.jam文件并附加以下文本:

import os ;
androidNDKRoot = C:/android-ndk-r8e ; # put the relevant path
 using gcc : android :
     $(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-g++ :
     <compileflags>--sysroot=$(androidNDKRoot)/platforms/android-9/arch-arm
     <compileflags>-mthumb
     <compileflags>-Os
     <compileflags>-fno-strict-aliasing
     <compileflags>-O2
     <compileflags>-DNDEBUG
     <compileflags>-g
     <compileflags>-lstdc++
     <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.7/include
     <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi/include
     <compileflags>-D__GLIBC__
     <compileflags>-D_GLIBCXX__PTHREADS
     <compileflags>-D__arm__
     <compileflags>-D_REENTRANT
     <archiver>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-ar
     <ranlib>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-ranlib
         ;

当然,你必须把NDK的正确位置放在你的电脑上,而不是c:/android-ndk-r8e

此外,您可以选择更新的平台API,而不是android-9

还要注意,NDK提供了几个工具链,上面的设置指向gcc-4.7。如果您更喜欢使用其他工具链构建boost,请将arm-linux-androideabi-4.7更改为相关路径。

将配置放入user-config.jam后,将cmdcd打开到Boost所在的目录,然后调用bootstrap。然后像这样调用b2(例如):

b2 --without-python --without-serialization threading=multi link=static runtime-link=static toolset=gcc-android target-os=linux threadapi=pthread --stagedir=android stage

更新:截至2015年11月,较旧的NDK工具链似乎与较新的Boost版本存在问题,导致编译器崩溃,因此请考虑使用较新的编译器。要做到这一点,只需将上面脚本中每出现4.7次更改为4.9次。此外,值得使用更新的Android API进行编译(例如andoid-9->andoid-16左右)。