android编译boost库

本文描述在Debian 8.0系统,Android NDK编译android版本的boost库,最后给出使用Android.mk及已编译好的库。

预备

andorod NDK版本:最高去到r10d目前最新的,建议android-ndk-r9d 支持的boost版本:1.45.0、1.48.0、1.49.0、1.53.0、1.54.0、1.55.0。

Boost-for-Android: https://github.com/MysticTreeGames/Boost-for-Android/archive/master.zip

编译boost库

如果不想编译就直接跳过,后面给出已经编译好的boost库

  1. 终端下执行sudo apt-get install ia32-libs,x64位缺少,请按提示安装。
  2. 配置环境变量:$(NDK_ROOT) ,依次执行:
    • export NDK_ROOT=/usr/local/src/android-ndk-r9d
    • export PATH=$NDK_ROOT:$PATH
  3. 修改build-android.sh的内容
    1.  --layout=versioned
       #增加下面两行
       --without-python
       --without-locale
       #增加结束
       -sICONV_PATH=`pwd`/../libiconv-libicu-android/armeabi 
  4. 终端执行: ./build-android.sh $(NDK_ROOT)

boost库的使用

1.你的程序Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS += -frtti -fexceptions

boost库的编译是用指定了gnustl的标准库。

2.你的程序Android.mk

#导入boost库所有在的目录
$(call import-add-path,$(LOCAL_PATH)/../../../../build)
..
..
LOCAL_WHOLE_STATIC_LIBRARIES += boost_static
include $(BUILD_STATIC_LIBRARY)
$(call import-module,boost)

3.boost 库的Android.mk文件内容

LOCAL_PATH:= $(call my-dir)
# boost_date_time
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_date_time
LOCAL_SRC_FILES := lib/libboost_date_time-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)

# boost_filesystem
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_filesystem
LOCAL_SRC_FILES := lib/libboost_filesystem-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)

# boost_thread
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_thread
LOCAL_SRC_FILES := lib/libboost_thread-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)

# boost_system
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_system
LOCAL_SRC_FILES := lib/libboost_system-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)

# boost_program_options
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_program_options
LOCAL_SRC_FILES := lib/libboost_program_options-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)

# boost_chrono
#
#include $(CLEAR_VARS)
#LOCAL_MODULE := boost_chrono
#LOCAL_SRC_FILES := lib/libboost_chrono-gcc-mt-1_55.a
#include $(PREBUILT_STATIC_LIBRARY)

# first lib, which will be built statically
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_static
LOCAL_MODULE_FILENAME := boost
LOCAL_STATIC_LIBRARIES := boost_date_time
                          boost_system
                          boost_filesystem
                          boost_program_options
                          boost_thread
                         # boost_chrono
#LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/boost-1_55
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/boost-1_55
#LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
include $(BUILD_STATIC_LIBRARY)

 编译好的boost 1.55的下载

build ndk-r9d-boost1.55.0:http://pan.baidu.com/s/1pJKH6gr