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?
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.
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.
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.
I've solved the problem. I specified the incorrect path to NDK. Script patches CrystaX NDK too. So now it works!
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.
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
Build boost.Build tool, in Boost prj:
./bootstrap.sh
echo "using gcc : android : arm-linux-androideabi-g++ ;" > $HOME/user-config.jam
Build example
./b2 --prefix=$HOME/mybuild --with-thread --with-system toolset=gcc-android threading=multi link=static install
I hope these can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With