Compile and use boost for Android NDK R10e

12,720

Solution 1

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 ? :)

Solution 2

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

Solution 3

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"

Share:
12,720

Related videos on Youtube

BSod
Author by

BSod

Updated on September 16, 2022

Comments

  • BSod
    BSod over 1 year

    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 do not succeed. When I try compiling it with bjam, I get the following error:

    error: toolset gcc initialization:
    
    error: version 'androidR10e' requested but 'g++-androidR10e' not found and version '4.2.1' of default 'g++' does not match
    error: initialized from /path/to/android-ndk-r10e/sources/boost/tools/build/v2/user-config.jam:86
    

    Has anyone successfully used Boost with Android NDK R10e?

    And when I can compile it, how should I do to use it in my Android app project?

  • BSod
    BSod almost 9 years
    I ended up using a prebuilt Boost library I found. It works but I'll try to compile with your advice as well. Thanks! github.com/emileb/Boost-for-Android-Prebuilt
  • Antonio
    Antonio over 8 years
    Can you be a little bit more precise about the operations to be done? I do not have a project-config.bjam file for example.
  • IgorGanapolsky
    IgorGanapolsky almost 8 years
    No, there is no Boost library folder in crystax-ndk-10.3.1.