I have written a lot of projects developed using the boost library in the past, and recently I have prepared to transplant some code to Android (I have not studied the upper-layer interface or the JNI layer, now, only the code porting and compilation are completed. Other people are responsible for how to call the code. So the first thing to solve is the porting problem of the boost library itself.
I found some related information on Google, and then found a powerful post on the http://stackoverflow.com:
Http://stackoverflow.com/questions/14036311/official-boost-library-support-for-android-and-ios/14089965#comment19511559_14089965
The post roughly introduces how to install the tool. It involves a script tool written by a foreigner for compiling.
The porting process was relatively smooth, but the ndk r8d downloaded at the beginning seemed to have requirements for glibc versions. When compiling its own sample on centos5.6 on my side, arm-Linux-androideabi-LD prompts that the glibc version in/usr/lib/libstdc ++ is too low to execute the link. It is possible that arm-Linux-androideabi-LD depends on the library of the later version, you have time to update it and check again. Oh my God! But I didn't care about it, so there is ndk R8 IN THE SYSTEM. Let's talk about the compilation process.
1. Download and install ndk
The R8 I used is placed in/Usr/local/src/android-ndk-r8
Register environment variables (the first sentence must be executed ):
Exports ndk_root =/usr/local/src/android-ndk-r8
Export Path = $ ndk_root: $ path
2. Download the boost-for-android Tool
Git clone git: // github.com/madadam/boost-for-android.git
It contains the boost patch and compilation script, which is placed in/Usr/local/src/Boost-for-android
3. Download boost_1.49.0
Currently, the above tools only support patching up to 1.49. In addition, the boost-for-android script itself provides the function of downloading the boost compressed package, but the speed of tianchao... You know, it's faster to use a download tool.
Place the downloaded boost_1.49.0.tar. BZ in/Usr/local/src/Boost-for-android
4. Start Compilation
Switch directory/Usr/local/src/Boost-for-android
Run:
./Build-android.sh -- boost = 1.49.0 $ ndk_root
Compilation is successful if no exceptions occur. You can view other compilation options on your own.
The generated file is located in/Usr/local/src/Boost-for-android/build
5. Test demo
I have extracted one from the boost sample for compilation testing (./boost_000049_0/libs/ASIO/example/allocation/server. cpp)
Create in any locationJNIFolder, putServer. cppAnd createAndroid. mk, The compilation content is as follows:
LOCAL_PATH := $(call my-dir)BOOST_VERSION := 1_49PROJECT_ROOT := $(LOCAL_PATH)BOOST_INCLUDE_PATH := /usr/local/src/Boost-for-Android/build/include/boost-1_49BOOST_LIB_PATH := /usr/local/src/Boost-for-Android/build/lib# Path and name of the STL library. Add this to the *end* of LOCAL_LDLIBS.# Note this is a hack/workaround to prevent linker errors when compiling with # boost. STL_LIBS := -L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/armeabi \ -lgnustl_staticinclude $(CLEAR_VARS)LOCAL_MODULE := boost_testLOCAL_C_INCLUDES:= $(BOOST_INCLUDE_PATH) \ $(PROJECT_ROOT)LOCAL_SRC_FILES := server.cppLOCAL_LDLIBS := -llog# The order of these libraries is often important.LOCAL_LDLIBS += -L$(BOOST_LIB_PATH) \ -lboost_system-gcc-mt-$(BOOST_VERSION) \ -lboost_thread-gcc-mt-$(BOOST_VERSION) # $(STL_LIBS)include $(BUILD_EXECUTABLE)
Create againApplication. mkThe content is as follows:
APP_STL := gnustl_staticAPP_CPPFLAGS += -frtti -fexceptions
RunNdk-build
Now you should have compiled successfully. Congratulations.