18

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
  • 193
  • 1
  • 2
  • 6

5 Answers5

6

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

brainsandwich
  • 472
  • 3
  • 10
  • I ended up using a prebuilt Boost library I found. It works but I'll try to compile with your advice as well. Thanks! https://github.com/emileb/Boost-for-Android-Prebuilt – BSod May 30 '15 at 09:54
  • 3
    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. – Antonio Oct 28 '15 at 11:29
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

Dmitry Moskalchuk
  • 1,249
  • 8
  • 12
1

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

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!

Community
  • 1
  • 1
Antonio
  • 19,451
  • 13
  • 99
  • 197
0

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.

Declan
  • 669
  • 1
  • 7
  • 12