我使用的是android-ndk-r10b版本,NDK在7以后就不需要依赖于cygwin了
1. boost官网下载boost_1_55_0.tar.gz,(https://sourceforge.net/projects/boost/files/boost/1.55.0/)解压放在e:\下, 解压后的文件名: boost_1_55_0
2. 启动Windows PowerShell(这个比cmd好些)。
3. 生成boost编译工具: 进入boost目录,运行 bootstrap.bat 生成 b2.exe
4. 修改 <boost>/tools/build/v2/user-config.jam 内容修改如下:
import os ;
if [ os.name ] = CYGWIN || [ os.name ] = NT {
androidPlatform = windows-x86_64 ;
compilerTool = x86-4.6 ;
androidTargetSys = i686 ;
androidArch = x86 ;
androideabi = android ;
}
else if [ os.name ] = LINUX {
androidPlatform = linux-x86_64 ;
}
else if [ os.name ] = MACOSX {
androidPlatform = darwin-x86 ;
}
modules.poke : NO_BZIP2 : 1 ;
#ANDROID_NDK Path
ANDROID_NDK = D:/Android/android-ndk-r10b ;
using gcc : android4.6 : $(ANDROID_NDK)/toolchains/$(compilerTool)/prebuilt/$(androidPlatform)/bin/$(androidTargetSys)-linux-$(androideabi)-g++ :
<archiver>$(ANDROID_NDK)/toolchains/$(compilerTool)/prebuilt/$(androidPlatform)/bin/$(androidTargetSys)-linux-$(androideabi)-ar
<ranlib>$(ANDROID_NDK)/toolchains/$(compilerTool)/prebuilt/$(androidPlatform)/bin/$(androidTargetSys)-linux-$(androideabi)-ranlib
<compileflags>--sysroot=$(ANDROID_NDK)/platforms/android-9/arch-$(androidArch)
<compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.6/include
<compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include
<compileflags>-DNDEBUG
<compileflags>-D__GLIBC__
<compileflags>-DBOOST_FILESYSTEM_VERSION=3
<compileflags>-lstdc++
<compileflags>-lgnustl_shared
<compileflags>-fno-strict-aliasing
<compileflags>-std=gnu++11
<compileflags>-O2
;
5.在PowerShell控制台,进入boost_1_55_0目录,输入下列命令:
.\b2.exe --without-python --without-mpi --without-serialization toolset=gcc-android4.6 link=static runtime-link=static target-os=linux --stagedir=android threadapi=pthread
等待漫长的boost编译生成 .a 静态库文件,这些文件最后生成在boost_1_55_0\android\lib目录下。
完成静态库生成完成后,完成下列步骤:
7. 在<boost>目录下,创建Android.mk, 内容如下
[plain]
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_atomic
LOCAL_SRC_FILES:= android/lib/libboost_atomic.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_chrono
LOCAL_SRC_FILES:= android/lib/libboost_chrono.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_context
LOCAL_SRC_FILES:= android/lib/libboost_context.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_date_time
LOCAL_SRC_FILES:= android/lib/libboost_date_time.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_exception
LOCAL_SRC_FILES:= android/lib/libboost_exception.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_filesystem
LOCAL_SRC_FILES:= android/lib/libboost_filesystem.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_graph
LOCAL_SRC_FILES:= android/lib/libboost_graph.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_iostreams
LOCAL_SRC_FILES:= android/lib/libboost_iostreams.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_c99
LOCAL_SRC_FILES:= android/lib/libboost_math_c99.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_c99f
LOCAL_SRC_FILES:= android/lib/libboost_math_c99f.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_c99l
LOCAL_SRC_FILES:= android/lib/libboost_math_c99l.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_tr1
LOCAL_SRC_FILES:= android/lib/libboost_math_tr1.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_tr1f
LOCAL_SRC_FILES:= android/lib/libboost_math_tr1f.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_tr1l
LOCAL_SRC_FILES:= android/lib/libboost_math_tr1l.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_program_options
LOCAL_SRC_FILES:= android/lib/libboost_program_options.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_random
LOCAL_SRC_FILES:= android/lib/libboost_random.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_regex
LOCAL_SRC_FILES:= android/lib/libboost_regex.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_system
LOCAL_SRC_FILES:= android/lib/libboost_system.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
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)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_timer
LOCAL_SRC_FILES:= android/lib/libboost_timer.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
可以根据自己的需要调整以上包含
-------------------------------------------------------------------------------------------------------------
应用程序设置:
1. 在应用程序的Android.mk中添加
LOCAL_WHOLE_STATIC_LIBRARIES += boost_filesystem
LOCAL_WHOLE_STATIC_LIBRARIES += boost_system
用多少, 包多少
添加异常支持 LOCAL_CPPFLAGS += –fexceptions
添加模块引用 $(call import-module, boost_1_55_0)
2. 在应用程序的Application.mk中添加
[plain]
#使用stlport_static选项时,与boost一起使用,会在链接时产生如下错误:
# undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
APP_STL := gnustl_static #stlport_static