【问题标题】:How to compile boost 1.68.0 for Android using NDK r18b using Windows如何使用 Windows 使用 NDK r18b 为 Android 编译 boost 1.68.0
【发布时间】:2019-01-24 14:46:31
【问题描述】:

我必须使用 NDK r18b 为 Android 构建一个 boost 版本,我很难做到这一点,所以我在这里发布 Question+Answer 因为它可能对其他人有所帮助。

首先,我尝试了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编译的步骤是什么?

【问题讨论】:

    标签: android c++ boost android-ndk


    【解决方案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到boost文件夹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(未测试)

    【讨论】:

      【解决方案2】:

      感谢您的帮助。

      moritz-wundke/Boost-for-Android 是一个很棒的项目,也是最初的 Boost-for-Android。但是,它的工作方式需要持续维护,以便在新版本出现时支持 ndk 和 boost 的每个新组合(您只能为项目已配置支持的显式版本构建)。经过很长一段时间(boost version 1.53 -> 1.63, and ndk 10->16),该项目似乎不再被维护,并且我与维护者联系的努力都是徒劳的,我决定分叉它,即为什么dec1/Boost-for-Android 应运而生。

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

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

      我很确定它也可以在 windows 或 mac 上运行(可能比您在上面花费的精力更少),但是使用虚拟机(例如免费的虚拟机)进行构建要容易得多,如果您真的想在那里开发,请将生成的二进制文件复制到 Windows。

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

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

      【讨论】:

      • 谢谢。多亏了我分析的你的 sh 脚本,最终可以完成它。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      • 2014-02-14
      • 2011-08-15
      • 2015-03-10
      相关资源
      最近更新 更多