Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NDK: Including boost c++ library

I am trying to use a boost library inside my android application, using the NDK. I have found a couple of success stories here and here, but I can't say the same about me. I am specifically trying to use the library in this link, as well as the boost thread library. In the code below, I am only trying to include the thread library, not the math library. The process I used to build the boost libraries is pretty much the same as the first link I attached.

So far, it seems I have successfully built the boost libraries, but when I run ndk-build, I get the following error:

Prebuilt       : libboost_thread.a <= <NDK>/sources/ cp: omitting directory `path/to/ndk/sources/boost' make: *** [obj/local/armeabi/libboost_thread.a] Error 1 

Obviously the cp: omitting directory... is not exactly an error. But the only thing I'm getting other than that is the next line, which doesn't really mean anything. Error 1

Here's my Android.mk file:

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_STATIC_LIBRARIES := boost_thread LOCAL_LDLIBS := lboost_system-gcc-md lboost_thread-gcc-md -lgnustl_static LOCAL_LDLIBS += lboost_system-gcc-md lboost_thread-gcc-md \          -L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/armeabi \          -lgnustl_static   LOCAL_SRC_FILES := #cpp_sources LOCAL_MODULE := com_example_ndkFile_CppMethods include $(BUILD_SHARED_LIBRARY) $(call import-module,boost)  

And there's also an Android.mk file in path/to/ndk/sources/boost/:

LOCAL_PATH:= $(call my-dir)   include $(CLEAR_VARS)   LOCAL_MODULE:= boost_thread LOCAL_SRC_FILES:= android/lib/libboost_thread.a   LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)   include $(PREBUILT_STATIC_LIBRARY) 

And my humble Application.mk file:

APP_ABI := armeabi armeabi-v7a APP_STL := gnustl_static APP_CPPFLAGS = -fexceptions   

I built the boost libraries using bjam. All of the libboost_###.a files are in the sources/boost/android/lib folder.

What is the error I'm getting?

like image 889
naxchange Avatar asked Mar 13 '13 04:03

naxchange


People also ask

Is NDK necessary for Android studio?

Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE's integrated build system. Your Java code can then call functions in your native library through the Java Native Interface (JNI) framework.

What compiler does Android NDK use?

Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++.

Is boost free C++?

Welcome to Boost.org!Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications.


1 Answers

I built the boost libraries using Boost-for-Android. Then I have in my boost/include/lib directory the android makefile boost.mk

LOCAL_PATH := $(call my-dir)  # boost_date_time # include $(CLEAR_VARS) LOCAL_MODULE := boost_date_time LOCAL_SRC_FILES := libboost_date_time-gcc-mt-1_53.a include $(PREBUILT_STATIC_LIBRARY)  # boost_filesystem # include $(CLEAR_VARS) LOCAL_MODULE := boost_filesystem LOCAL_SRC_FILES := libboost_filesystem-gcc-mt-1_53.a include $(PREBUILT_STATIC_LIBRARY)  # boost_thread # include $(CLEAR_VARS) LOCAL_MODULE := boost_thread LOCAL_SRC_FILES := libboost_thread-gcc-mt-1_53.a include $(PREBUILT_STATIC_LIBRARY)  # boost_system # include $(CLEAR_VARS) LOCAL_MODULE := boost_system LOCAL_SRC_FILES := libboost_system-gcc-mt-1_53.a include $(PREBUILT_STATIC_LIBRARY)  # boost_program_options # include $(CLEAR_VARS) LOCAL_MODULE := boost_program_options LOCAL_SRC_FILES := libboost_program_options-gcc-mt-1_53.a include $(PREBUILT_STATIC_LIBRARY)  # boost_chrono # include $(CLEAR_VARS) LOCAL_MODULE := boost_chrono LOCAL_SRC_FILES := libboost_chrono-gcc-mt-1_53.a include $(PREBUILT_STATIC_LIBRARY) 

and my module where i use some of the boost libraries looks like this

LOCAL_PATH := $(call my-dir)  # SignalServer, executable  # include $(CLEAR_VARS) LOCAL_CFLAGS           := -DTIXML_USE_TICPP #LOCAL_CFLAGS           += -DDEBUG LOCAL_STATIC_LIBRARIES := boost_thread \     boost_system \     boost_filesystem \     boost_program_options \     boost_chrono \ LOCAL_STATIC_LIBRARIES += ticpp \     tia \     tobicore \     tobiid \     tid \     gdf LOCAL_MODULE           := signalserver LOCAL_C_INCLUDES       := $(LOCAL_PATH)/include LOCAL_C_INCLUDES       += $(LOCAL_PATH)/extern/include LOCAL_C_INCLUDES       += $(LOCAL_PATH)/../boost/include/boost-1_53 LOCAL_SRC_FILES        := #cpp source  include $(BUILD_EXECUTABLE) 

in addition I have an Android.mk where all subdir makefiles are listed

TOP_PATH := $(call my-dir)  include $(TOP_PATH)/boost/lib/boost.mk include $(TOP_PATH)/signalserver/signalserver.mk . . 

and my Application.mk:

APP_PLATFORM          := android-14 APP_ABI               := armeabi-v7a #APP_OPTIM             := debug #NDK_DEBUG             := 1  NDK_TOOLCHAIN_VERSION := 4.6 APP_STL               := gnustl_static APP_CPPFLAGS          := -fexceptions -frtti 
like image 90
tlimbacher Avatar answered Sep 28 '22 17:09

tlimbacher