如何使用Windows在NDK r18b上为Android编译Boost 1.68.0

时间:2019-01-24 14:46:32

标签: android c++ boost android-ndk

我不得不使用NDK r18b构建Android的boost版本,我很难实现这一目标,所以我在此处发布Question + Anwer,因为它可能会对其他人有所帮助。

首先,我尝试了https://github.com/moritz-wundke/Boost-for-Android,但这没有成功,请参见How to build boost 1.69.0 for Android with NDK r18b using moritz-wundke/Boost-for-Android?

其次,我尝试了https://github.com/dec1/Boost-for-Android,但这也没有成功,请参见How to build boost 1.69.0 for Android with NDK r18b using dec1/Boost-for-Android?

要实现Boost的编译要遵循哪些步骤?

2 个答案:

答案 0 :(得分:1)

实际上,这些脚本是为Linux设计的,几乎无法在Windows下运行。然后,我从头开始,终于可以在Windows下找到合适的配置来实现这一目标。我基本上检查了其他库的编译方式(我使用QtCreator在Android上进行部署,因此编译窗口向我报告了如何调用clang ++,因此我在此基础上编写了一个user-config.jam。

以下是使用NDK r18b为Android armeabiv7和x86编译boost 1.68.0的步骤:

然后设置一些环境变量:

set ANDROIDNDKROOT=C:\Android\android-ndk-r18b (change this accordingly)
set NDKVER=r18b
set CLANGPATH=%ANDROIDNDKROOT%\toolchains\llvm\prebuilt\windows-x86_64\bin

复制user-config.jam以增强文件夹tools/build/src

import os ;
local AndroidNDKRoot = [ os.environ ANDROIDNDKROOT ] ;
local AndroidBinariesPath = [ os.environ CLANGPATH ] ;

using clang : armeabiv7a
:
$(AndroidBinariesPath)/clang++
:
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-mthumb
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-fstack-protector-strong
<compileflags>-Wno-invalid-command-line-argument
<compileflags>-Wno-unused-command-line-argument
<compileflags>-no-canonical-prefixes
<compileflags>-I$(AndroidNDKRoot)/sources/cxx-stl/llvm-libc++/include
<compileflags>-I$(AndroidNDKRoot)/sources/cxx-stl/llvm-libc++abi/include
<compileflags>-I$(AndroidNDKRoot)/sources/android/support/include
<compileflags>-DANDROID
<compileflags>-Wa,--noexecstack
<compileflags>-Wformat
<compileflags>-Werror=format-security
<compileflags>-DNDEBUG
<compileflags>-D_REENTRANT
<compileflags>-O2
<compileflags>-gcc-toolchain
<compileflags>$(AndroidNDKRoot)/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64
<compileflags>-target
<compileflags>armv7-linux-androideabi
<compileflags>-march=armv7-a
<compileflags>-mfloat-abi=softfp
<compileflags>-mfpu=vfp
<compileflags>-fno-builtin-memmove
<compileflags>-fpic
<compileflags>-DHAVE_CONFIG_H
<compileflags>-fno-integrated-as
<compileflags>--sysroot
<compileflags>$(AndroidNDKRoot)/sysroot
<compileflags>-isystem
<compileflags>$(AndroidNDKRoot)/sysroot/usr/include/arm-linux-androideabi
<compileflags>-D__ANDROID_API__=18
<archiver>$(AndroidNDKRoot)/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/arm-linux-androideabi/bin/ar
<ranlib>$(AndroidNDKRoot)/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/arm-linux-androideabi/bin/ranlib

;

# --------------------------------------------------------------------

using clang : x86
:
$(AndroidBinariesPath)/clang++
:
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-mthumb
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-fstack-protector-strong
<compileflags>-Wno-invalid-command-line-argument
<compileflags>-Wno-unused-command-line-argument
<compileflags>-no-canonical-prefixes
<compileflags>-I$(AndroidNDKRoot)/sources/cxx-stl/llvm-libc++/include
<compileflags>-I$(AndroidNDKRoot)/sources/cxx-stl/llvm-libc++abi/include
<compileflags>-I$(AndroidNDKRoot)/sources/android/support/include
<compileflags>-DANDROID
<compileflags>-Wa,--noexecstack
<compileflags>-Wformat
<compileflags>-Werror=format-security
<compileflags>-DNDEBUG
<compileflags>-D_REENTRANT
<compileflags>-O2
<compileflags>-gcc-toolchain
<compileflags>$(AndroidNDKRoot)/toolchains/x86-4.9/prebuilt/windows-x86_64
<compileflags>-target
<compileflags>i686-linux-android
<compileflags>-march=i686
<compileflags>-mfloat-abi=softfp
<compileflags>-mfpu=vfp
<compileflags>-fno-builtin-memmove
<compileflags>-fPIC
<compileflags>-mstackrealign
<compileflags>--sysroot
<compileflags>$(AndroidNDKRoot)/sysroot
<compileflags>-isystem
<compileflags>$(AndroidNDKRoot)/sysroot/usr/include/i686-linux-android
<compileflags>-D__ANDROID_API__=18
<archiver>$(AndroidNDKRoot)/toolchains/x86-4.9/prebuilt/windows-x86_64/i686-linux-android/bin/ar
<ranlib>$(AndroidNDKRoot)/toolchains/x86-4.9/prebuilt/windows-x86_64/i686-linux-android/bin/ranlib
;
  • 然后,对于armeabiv7-a:

    • 运行bjam -q --without-math --without-context --without-coroutine --without-fiber --without-python architecture=arm --ignore-site-config -j4 target-os=android toolset=clang-armeabiv7a link=static threading=multi --layout=tagged --build-dir=build/arm/%NDKVER% --stagedir=stage_arm_%NDKVER% stage
  • 然后,针对x86:

    • 运行bjam -q --without-math --without-context --without-coroutine --without-fiber --without-python architecture=arm --ignore-site-config -j4 target-os=android toolset=clang-armeabiv7a link=static threading=multi --layout=tagged --build-dir=build/arm/%NDKVER% --stagedir=stage_arm_%NDKVER% stage

希望可以按照相同的步骤来编译1.69.0(未经测试)

答案 1 :(得分:1)

感谢有用的说明。

moritz-wundke/Boost-for-Android是一个很棒的项目,也是原始的Android版Boost。但是,它的工作方式需要不断维护,以支持ndk的每个新组合并在新版本推出时提升功能(您只能针对已配置为项目支持的显式版本进行构建)。长时间(提升版本1.53-> 1.63,以及ndk 10-> 16)后,该项目似乎不再得到维护,而我与维护者联系的努力也徒劳,我决定分叉它,这是dec1/Boost-for-Android为何存在。

它的优点是通常不需要更新以支持google的ndk或boost的新版本。它们通常是开箱即用的,或者需要很少的调整(但是我仍然定期进行测试以确保)。

使用dec1/Boost-for-Android可以说也更简单(肯定比按照上面的说明进行操作)。您可以在一行代码中一次性完成针对任何/所有架构(arm64-v8a,armeabi-v7a,x86,x86_64)的构建。而且,如果您不需要自定义版本,则可以从here下载预编译的二进制文件(增强版1.69.0,使用ndk 19和18b,现在还可以使用动态和静态)。还有一个example app可帮助您测试构建。

我很确定它也可以在Windows或Mac上运行(可能比您在上面花费的精力少),但是仅使用虚拟机(例如免费的virtualbox)进行构建会容易得多,如果您确实要在Windows上进行开发,请将其复制到Windows。

Nonetheles,moritz-wundke / Boost-for-Android似乎最近收到了新的贡献,这对每个人来说都是个好消息。而且,如果您发现它更适合在Windows(或任何其他平台)上构建增强功能,那就太好了。

祝您的项目好运,并再次感谢您的见解。