我必须使用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的编译需要遵循哪些步骤?

最佳答案

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

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

  • 从boost.org下载boost 1.68.0:https://www.boost.org/users/history/version_1_68_0.html
  • 应用moritz-wundke的补丁程序,否则它将无法编译(顺便感谢)。从这里获取:https://github.com/moritz-wundke/Boost-for-Android/tree/master/patches
  • 运行bootstrap.bat(您需要它来找到编译器,我已经安装了VS 2015,因此可以正常使用)

  • 然后设置一些环境变量:
    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(未经测试)

    07-24 09:44
    查看更多