15

Has somebody ported and used Boost on Android?

I've found the tool which builds boost for android (https://github.com/MysticTreeGames/Boost-for-Android), the build is successful, and i've got static boost libs. But when i'm tring to use it in simple android app:

#include <jni.h>
#include "boost/thread.hpp"

void f()
{
};

i've got a lot of compilation errors: redefinitions, undeclared etc. Seems it concerns NDK std headers. My Android.mk looks like:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

TARGET_PLATFORM := android-8

LOCAL_MODULE := Boost

LOCAL_CFLAGS := -DMYSTIC -I$(LOCAL_PATH)/boost/include/ 
LOCAL_LDLIBS := -L$(LOCAL_PATH)/external/boost/lib/

LOCAL_CPPFLAGS  := -fexceptions
LOCAL_CPPFLAGS  += -frtti
LOCAL_CPPFLAGS  += -DBOOST_THREAD_LINUX
LOCAL_CPPFLAGS  += -DBOOST_HAS_PTHREADS
LOCAL_CPPFLAGS  += -D__arm__
LOCAL_CPPFLAGS  += -D_REENTRANT
LOCAL_CPPFLAGS  += -D_GLIBCXX__PTHREADS
LOCAL_CPPFLAGS  += -DBOOST_HAS_GETTIMEOFDAY

LOCAL_SRC_FILES := main.cpp

include $(BUILD_SHARED_LIBRARY)

Also I tried to build with Crystax_NDK_r4 and Android_NDK_r5b but it hasn't resolved the problem.

Any ideas?

derekerdmann
  • 17,696
  • 11
  • 76
  • 110
ackio
  • 662
  • 1
  • 5
  • 12
  • You should paste your linker errors here too. Verbatim. Very few correspondents have the time to try to replicate your setup, but good error messages will help clue readers in to what's going on. – C. K. Young Feb 03 '11 at 05:40

3 Answers3

7

I've solved the problem. I specified the incorrect path to NDK. Script patches CrystaX NDK too. So now it works!

ackio
  • 662
  • 1
  • 5
  • 12
4

I just found a easy way to build boost under android NDK, which don't need patching the boost.

I don't use Android.mk to build boost, instead, I use the standalone-toolchain to build, just link CodeSourcery's toolchain.

  1. Prepare the NDK toolchain first:

    Install the NDK toolchain as a standalone toolchain. See $NDK/docs/STANDALONE-TOOLCHAIN.html

    Add the bin path of cross-toolchain to your PATH

  2. Build boost.Build tool, in Boost prj:

    ./bootstrap.sh

  3. echo "using gcc : android : arm-linux-androideabi-g++ ;" > $HOME/user-config.jam

  4. Build example

    ./b2 --prefix=$HOME/mybuild --with-thread --with-system toolset=gcc-android threading=multi link=static install

I hope these can help you.

ryanking
  • 309
  • 2
  • 6
1

You can download a collection of scripts that will download and build some popular c/c++ open source libraries for android and ios including boost at this location.

https://github.com/mevansam/cmoss

mks
  • 21
  • 2