Boost Support for Android.

1,923 views
Skip to first unread message

Chiranjeev Gupta

unread,
Jul 6, 2016, 10:01:27 AM7/6/16
to android-ndk
I have been working on a project to port existing core C/C++ libraries to Android and am doing so using Android NDK. I am using Android Studio as my IDE. I was following this. I was trying to include the boost support for my application so as to build a shared library of the source code files which indeed include boost header files.  To give you a idea of what I have done till now, its my humble request to please review this fork. 

I had used Boost-for-Android-Prebuilt which uses Boost version _1_53_0. 

I am stuck at this for more than a week. Any help or suggestion from your side will be very helpful.

mic _

unread,
Jul 6, 2016, 10:21:09 AM7/6/16
to andro...@googlegroups.com
Which boost libraries do you need specifically?
Personally, I found it easier to ditch boost's build tools (b2, etc) and write my own Android.mk files for each library that I needed. Those makefiles would generally be quite short, just listing the necessary source files, and then I'd have a boost "master makefile" one or two directory levels up that sets some necessary compilation flags and does "include $(call all-subdir-makefiles)".

Also, I built static libraries out of the boost libraries, which I then linked into my main shared library by adding them to LOCAL_STATIC_LIBRARIES.

/Michael


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/59350112-215b-428e-945e-629bd99b0636%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chiranjeev Gupta

unread,
Jul 6, 2016, 4:32:59 PM7/6/16
to android-ndk
I did build static libraries following this tutorial. Then as you had suggested did make the build files and included the specific libraries needed for it to work. But then there was error during the build. The archive lbraries (.a files) were not compatible . If you have worked out through this can you please give me some specific steps, and help me resolve this problem. 
Eagerly waiting for your reply and thanks 
:)))

mic _

unread,
Jul 7, 2016, 4:27:10 AM7/7/16
to andro...@googlegroups.com
You built everything using the NDK, right?

Writing the necessary makefiles is pretty straight-forward. Your main Android.mk would look something like:

LOCAL_PATH := $(call my-dir)
this_LOCAL_PATH := $(LOCAL_PATH)

BOOST_ROOT := path/to/boost/directory

# Build boost libraries
include $(BOOST_ROOT)/Android.mk

include $(CLEAR_VARS)
LOCAL_PATH := $(this_LOCAL_PATH)
LOCAL_MODULE := mysharedlib
LOCAL_STATIC_LIBRARIES := boost_date_time  # and any other libraries that you've built and want to use

# Other stuff: specify source/include files, set compilation flags, etc.

include $(BUILD_SHARED_LIBRARY)


boost\Android.mk:

# Set flags as you see fit - this is just an example. Note that for armeabi you will need to make sure that shared pointers and atomic operations
# use software-synchronization. Consult the boost documentation.
BOOST_CPPFLAGS := -fexceptions -pthread
BOOST_CPPFLAGS += -DANDROID -D_REENTRANT -D_GLIBCXX__PTHREADS

include $(call all-subdir-makefiles)


boost\libs\Android.mk:

include $(call all-subdir-makefiles)


boost\libs\date_time\Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := boost_date_time

LOCAL_CPPFLAGS += $(BOOST_CPPFLAGS)
LOCAL_C_INCLUDES += $(BOOST_ROOT)
SRC_FILES_LIST := $(wildcard $(LOCAL_PATH)/src/gregorian/*.cpp)
SRC_FILES_LIST += $(wildcard $(LOCAL_PATH)/src/posix_time/*.cpp)
LOCAL_SRC_FILES := $(SRC_FILES_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_STATIC_LIBRARY)


And so on for any other non-include-only boost library that you want to use.

/Michael


Chiranjeev Gupta

unread,
Jul 13, 2016, 10:53:42 AM7/13/16
to android-ndk
Can you please help me figure out which linker flag should I use in order to resolve this. Thanks again:))

Chiranjeev Gupta

unread,
Jul 13, 2016, 10:53:42 AM7/13/16
to android-ndk
Thanks mic !! Sorry for my late reply, my laptop just returned for the service center. I will keep you updated with my endeavor, and thanks for guiding me . :)) 

Daniel Wright

unread,
Jul 19, 2016, 1:43:52 AM7/19/16
to android-ndk
Hi Chiranjeev,


Have you thought about using the CrystaX NDK? It's a third party fork of Google's version, and it has so many more libraries that come along with it - including boost_1_59_0. I use CrystaX instead of the regular NDK now, since Google has ignored numerous issues that have come about with the regular NDK. 

You can download CrystaX here: https://www.crystax.net/en/download

- Daniel

Dan Albert

unread,
Jul 19, 2016, 1:48:15 AM7/19/16
to android-ndk
since Google has ignored numerous issues that have come about with the regular NDK. 

Anything in particular you want to point out? We've been making a lot of improvements in the past year, and there's still a lot in the pipe. 

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Daniel Wright

unread,
Jul 20, 2016, 2:36:17 AM7/20/16
to android-ndk
Mainly:

1)
The sudden exclusion of the NDK RenderScript APIs after r10 (which I've seen on the bug tracker too). I saw some "resolution" that was only the lines of "it will be included when we do more regressions in future versions."

2)
While this is an old topic, I wish OpenCL apis were at least considered -- even though it's not available across all devices. This, in my opinion, is similar to the GLES 2.0/3.0 situation, where you can fall back to 2.0 API if GLES 3.0 isn't available (but has had wrapper classes since API 18). Not a big deal though, since vendors such as Qualcomm have released their own SDKs for such a purpose.

3) 
As you've implied, up until recently, I haven't seen much of a direction or focus on the NDK/native end of documentation, instrumentation, etc. Consequently, I switched to CrystaX, mainly for more language features support (e.g. wide char). It's made including commonly used libraries (like boost) a lot less tedious.

4)
Extremely poor debugging support. While you can debug natively in AS, I find the AS NDK support extremely limited. I have a very meticulous compiling system for my framework which means I do not have the typical layout of an NDK project. It would be extremely helpful if I could simply "import" my C++/native source code while using LLDB to debug my framework. However, this is not the case. I must include C++ code in order to actually get the debugging capability of source code. Extremely frustrating, but not really the NDK team's responsibility, I'm assuming. 

I mainly work on computationally intensive (thus the desire for RenderScript/OpenCL) applications. As such, I try to avoid Java as much as possible. Issue #1 stated above has been very inconvenient for me. I've had to manually include RenderScript APIs by building them from AOSP, since I can't seem to find the old version of the NDK that has the binaries. 

Chiranjeev Gupta

unread,
Jul 20, 2016, 11:00:48 AM7/20/16
to android-ndk
Thanks Daniel for the suggestion. Actually I tried using it but the very first ndk-build command gave me permisssion denied. :/ Is there any step by step guide as to how should I install and make it work. Please guide me :))

Chiranjeev Gupta

unread,
Jul 20, 2016, 11:00:48 AM7/20/16
to android-ndk
Hello Dan, thanks for helping me throughout. Right now I am just concerned as to what is causing these errors. The main cause of these errors is yet to be identified and needed your help in doing so. 

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

Error:error: undefined reference to 'std::runtime_error::runtime_error(std::string const&)'

Error:error: undefined reference to 'std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'

Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

Error:error: undefined reference to 'std::basic_string, std::allocator >::~basic_string()'

Error:error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator const&)'

Error:error: undefined reference to 'std::runtime_error::runtime_error(std::string const&)'

Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(std::string const&)'

Error:error: undefined reference to 'std::_Rb_tree_increment(std::_Rb_tree_node_base*)'

Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(std::string const&)'

Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'

Error:error: undefined reference to 'std::_Rb_tree_increment(std::_Rb_tree_node_base const*)'

Error:error: undefined reference to 'std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'

Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(std::string const&)'

Error:error: linker command failed with exit code 1 (use -v to see invocation)

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'

Error:error: undefined reference to 'std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'

Error:error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator const&)'

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

Error:error: undefined reference to 'std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'


I myself am trying to figure out that "anything particular " you referrred to and unfortunately haven't :(. My work is stalled and damn I can't even find out what the actual issue is. Is it that the standard C++ libraries are not getting linked cause we are not using g++ / clang++ ? 

Dan Albert

unread,
Jul 20, 2016, 1:04:03 PM7/20/16
to android-ndk
How are you invoking the compiler when you get the undefined reference errors? Are you using ndk-build, make_standalone_toolchain.py, gradle, etc? It does look like you're not getting the C++ stdlib. For ndk-build the solution is setting `APP_STL := gnustl_static` (or s/static/shared) (that's what it looks like boost used, anyway). Other build systems might have different solutions, but standalone toolchains should just work in that regard.

Chiranjeev Gupta

unread,
Jul 21, 2016, 10:32:44 AM7/21/16
to android-ndk
Hello Daniel thanks for explaining me the facts and it sure looks interesting and worth looking at. unfortunately on my Mac I am able to use it. Can you provide me with some basic steps to initialise my experience with Crystax.Please help me start. And thanks again :))

Chiranjeev Gupta

unread,
Jul 21, 2016, 10:32:44 AM7/21/16
to android-ndk
I used idk-build previously , but had no success. Now I am using grade. That assemble task you get under the cradle build module, I am using that to build my code. I took reference from the hello-libs example of the google android-ndk master repository. So perhaps I should manually use idk-build with the configurations you have suggested. I'll try that and reply you quick. Thanks for your reply :))
Reply all
Reply to author
Forward
0 new messages