Compile and use boost for Android NDK R10e

前端 未结 5 597
面向向阳花
面向向阳花 2020-12-25 14:21

How do I compile and use Boost for the Android NDK? I\'ve tried everything I\'ve found online, from Boost for Android to compiling it myself with the bjam file. However, I d

相关标签:
5条回答
  • 2020-12-25 14:58

    Here: http://silverglint.com/boost-for-android/ you can find a simple and painless new way to build a modern (eg 1.64.0) version of boost for android. Works with clang and gcc.

    Also included is a sample app that shows you how to use the boost binaries thus built.

    0 讨论(0)
  • 2020-12-25 15:02

    The simplest way would be to use CrystaX NDK, which contains already built and ready-to-use Boost libraries. And here are examples how to use Boost with CrystaX NDK: 1, 2

    0 讨论(0)
  • 2020-12-25 15:04

    Following the boost directions, I was able to build boost 1.60 with NDKr10e on Ubuntu 12.04 (although I suspect very little depends on the host system). Here are my notes:

    get and unpack boost source tarball (i used 1.60): boost_1_60_0.tar.bz2

    moskewcz@maaya:/scratch/moskewcz/android/src$ ll
    total 74M
    drwx------ 10 moskewcz moskewcz 4.0K Mar  9 14:14 boost_1_60_0
    -rw-rw-r--  1 moskewcz moskewcz  74M Jan  5 11:15 boost_1_60_0.tar.bz2
    

    follow boost instructions in getting started on unix "Build Custom Binaries" section

    use a fresh, empty root to install b2 i.e. /scratch/boost-build-root; use usr as prefix; again following the boost instructions:

    moskewcz@maaya:/scratch/moskewcz/android/src/boost_1_60_0/tools/build$ ./bootstrap.sh
    moskewcz@maaya:/scratch/moskewcz/android/src/boost_1_60_0/tools/build$ ./b2 install --prefix=/scratch/moskewcz/android/boost-build-root/usr
    

    put b2 in path (again as per instructions)

    export PATH=/scratch/moskewcz/android/boost-build-root/usr/bin:$PATH
    

    in some jamfile (i had no ~/user-config.jam, so i created one and used that, maybe there's a better choice of jamfile to create/edit) add some jam-code (?) to define a gcc version (toolset) pointing to a g++ from a standalone toolchain. note that this is a toolchain created with the NDK in the normal fashion following its 'create a standalone toolchain' directions. i am NOT pointing to a g++ inside the NDK itself (that may or may not work, i dunno):

    import option ; 
    using gcc : arm_linux_android_4.9 : /scratch/android-stc/bin/aarch64-linux-android-g++ ; 
    option.set keep-going : false ;
    

    go to boost project root and build, mostly as per directions. --build-dir may be optional? also added -j8 to do || build

    moskewcz@maaya:/scratch/moskewcz/android/src/boost_1_60_0$ b2 -j8 --build-dir=bin.v2 toolset=gcc-arm_linux_android_4.9 stage
    

    note that this tries to build both static and shared libs by default, but building shared libs fails due to android not having librt.so -- according to my research, people claim that under android (some of?) the functionality of librt.so is inside libc.so -- so it may be okay to simply remove -lrt from the linking steps in order to build shared libs for android. i did not attempt this. see:

    https://code.google.com/p/android/issues/detail?id=5730

    Building Boost for Android with error "cannot find -lrt"

    0 讨论(0)
  • 2020-12-25 15:09

    I only managed to build with 10d. Cross compiling Linux->Android using Boost for Android worked straight away with that.

    To download a slightly outdated ndk, as not all ndk are immediately supported by Boost for Android, you can use this guide: Where do I find old versions of Android NDK?

    Note: I also wanted to specify the toolchain. I had to do it in 2 places:

    1. In build-android.sh, just after the line mentioned here above:

      TOOLCHAIN=${TOOLCHAIN:-arm-linux-androideabi-4.9}

    2. In the command line

      bash build-android.sh [ndk location] --toolchain=arm-linux-androideabi-4.9

    In fact, it worked better when I specified exactly which boost components I wanted with --with-libraries=[comma separated list].

    If instead I would build everything, I would get:

    ...failed updating 38 targets...

    ...skipped 6 targets...

    ...updated 10568 targets...

    ERROR: Failed to build boost for android!

    Done!

    0 讨论(0)
  • 2020-12-25 15:12

    We managed to compile it for NDKr10d. It should be the same for NDKr10e. The project-config.bjam should point to the gcc compiler from the NDK. Ours looks like this :

    import option ; 
    using gcc : arm : D:\\android\\ndk\\toolchains\\arm-linux-androideabi-4.9\\prebuilt\\windows-x86_64\\bin\\arm-linux-androideabi-g++.exe ; 
    option.set keep-going : false ; 
    

    Then just compile with b2, telling paths to android includes :

    b2 --reconfigure <your options>
        toolset=gcc-arm
        include=<ndk folder>\sources\cxx-stl\gnu-libstdc++\4.9\include
        include=<ndk folder>\sources\cxx-stl\gnu-libstdc++\4.9\libs\<target platform>\include
        include=<ndk folder>\platforms\<android api version>\arch-arm\usr\include
        install --libdir=stage\lib\<target platform>
    

    We're about to move to ndkr10e. Could you tell if boost still works with it ? :)

    0 讨论(0)
提交回复
热议问题