有个android项目上需要使用到boost标准c++库,Boost库是一个可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一,所以想将其移植到android系统上进行编译。
直接从网上下载 boost1.52版本,然后写makefile。。。进行编译,,碰到无数的编译错误。求助于google网络,终于发现一个好东东:
这里是使用NDK进行编译boost的但肯定对我有用吧。。经过一番折腾终于编译成功,,高兴,呵呵!
下面将主要的过程记录下来:
1、下载boost 源码:
由于https://github.com/MysticTreeGames/Boost-for-Android这里说明:
Boost for Android
Boost for android is a set of tools to compile the main part of the Boost C++ Libraries for the Android platform.
Currently supported boost versions are 1.45.0, 1.48.0 and 1.49.0.
因此下载最新的 1.49 版本,下载完成后进行打补丁
2、下载补丁代码
https://github.com/MysticTreeGames/Boost-for-Android/tree/master/patches/boost-1_49_0
3、打补丁代码
boost_1_49_0.tar.bz2 放在android的 external 下解压:
tar -xjvf external/boost_1_49_0.tar.bz2
将boost-1_49_0.patch放在external\boost_1_49_0下面根目录执行:
patch -Np1 -d external/boost_1_49_0 < external/boost_1_49_0/boost-1_49_0.patch
4、编写boost的makefile文件,即Android.mk
- LOCAL_PATH:= $(call my-dir)
- common_SRC_FILES := \
- libs/thread/src/pthread/thread.cpp \
- libs/thread/src/pthread/once.cpp \
- common_SRC_FILES += \
- libs/filesystem/v3/src/codecvt_error_category.cpp \
- libs/filesystem/v3/src/operations.cpp \
- libs/filesystem/v3/src/path.cpp \
- libs/filesystem/v3/src/path_traits.cpp \
- libs/filesystem/v3/src/portability.cpp \
- libs/filesystem/v3/src/utf8_codecvt_facet.cpp \
- libs/system/src/error_code.cpp \
- libs/system/src/local_free_on_destruction \
- include $(CLEAR_VARS)
- LOCAL_MODULE:= libboost
- LOCAL_SRC_FILES := $(common_SRC_FILES)
- <span style="color:#ff0000;">prebuilt_stdcxx_PATH := prebuilts/ndk/current/sources/cxx-stl/gnu-libstdc++
- LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/boost \
- $(prebuilt_stdcxx_PATH)/include \
- $(prebuilt_stdcxx_PATH)/libs/$(TARGET_CPU_ABI)/include/ \
- LOCAL_C_INCLUDES += \
- $(prebuilt_stdcxx_PATH)/include \
- $(prebuilt_stdcxx_PATH)/libs/$(TARGET_CPU_ABI)/include/ \
- $(prebuilt_supccxx_PATH)/include
- LOCAL_CFLAGS += -fvisibility=hidden -lpthread
- LOCAL_CPPFLAGS += -fexceptions -frtti
- LOCAL_SHARED_LIBRARIES := libc libstdc++ libstlport
- LOCAL_LDFLAGS += -L$(prebuilt_stdcxx_PATH)/libs/$(TARGET_CPU_ABI) -lgnustl_static -lsupc++</span>
- LOCAL_MODULE_TAGS := optional
- include $(BUILD_SHARED_LIBRARY)
比较重要的是上面 红色 部分文字
最后编译生成:
target thumb C++: libboost <= external/boost_1_49_0/libs/thread/src/pthread/thread.cpp
target thumb C++: libboost <= external/boost_1_49_0/libs/thread/src/pthread/once.cpp
target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/codecvt_error_category.cpp
target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/operations.cpp
target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/path.cpp
target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/path_traits.cpp
target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/portability.cpp
target thumb C++: libboost <= external/boost_1_49_0/libs/filesystem/v3/src/utf8_codecvt_facet.cpp
target thumb C++: libboost <= external/boost_1_49_0/libs/system/src/error_code.cpp
target SharedLib: libboost (out/target/product/godbox/obj/SHARED_LIBRARIES/libboost_intermediates/LINKED/libboost.so)
target Symbolic: libboost (out/target/product/godbox/symbols/system/lib/libboost.so)
target Strip: libboost (out/target/product/godbox/obj/lib/libboost.so)
Install: out/target/product/godbox/system/lib/libboost.so
成功生成 libboost.so 库