Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Port Boost to Android

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?

like image 273
ackio Avatar asked Feb 03 '11 05:02

ackio


People also ask

Does Boost work with C?

Boost can't be used with C as it uses OOP features from C++. It may be technically possible to develop a wrapper for it.

What is Boost ASIO?

Boost. Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach. An overview of the features included in Boost. Asio, plus rationale and design information.

How do I add boost to path?

Right-click example in the Solution Explorer pane and select Properties from the resulting pop-up menu. In Configuration Properties > Linker > Additional Library Directories, enter the path to the Boost binaries, e.g. C:\Program Files\boost\boost_1_46_1\lib\. From the Build menu, select Build Solution.


2 Answers

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

like image 184
ackio Avatar answered Oct 04 '22 06:10

ackio


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.

like image 29
ryanking Avatar answered Oct 04 '22 07:10

ryanking