1.Windows 平臺編譯
環境
Visual Studio 2015
boost 1.64
步驟
./bjam.exe stage --toolset=msvc-14.0 --without-graph --without-graph_parallel --stagedir="E:\boost_1_60_0\bin\vc14" link=static runtime-link=shared runtime-link=static threading=multi debug release
--without-graph --without-graph_parallel 指定不編譯的庫
等待庫編譯....2.Android 平臺編譯
import os ;
if [ os.name ] = CYGWIN || [ os.name ] = NT {
androidPlatform = windows-x86_64 ;
}
else if [ os.name ] = LINUX {
androidPlatform = linux-x86_64 ;
}
else if [ os.name ] = MACOSX {
androidPlatform = darwin-x86 ;
}
modules.poke : NO_BZIP2 : 1 ;
#ANDROID_NDK = ../.. ;
ANDROID_NDK = E:/Android/android-ndk-r11c ;
using gcc : android4.9 : $(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.9/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-g++ :
<archiver>$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.9/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ar
<ranlib>$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.9/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ranlib
<compileflags>--sysroot=$(ANDROID_NDK)/platforms/android-21/arch-arm
<compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.9/include
<compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include
#<compileflags>-DBOOST_NO_STD_WSTRING
<compileflags>-DBOOST_FILESYSTEM_VERSION=3
<compileflags>-lgnustl_shared
<compileflags>-mthumb
<compileflags>-Os
<compileflags>-fno-strict-aliasing
<compileflags>-O2
<compileflags>-DNDEBUG
<compileflags>-g
<compileflags>-lstdc++
<compileflags>-std=gnu++11
<compileflags>-D__GLIBC__
<compileflags>-D_GLIBCXX__PTHREADS
<compileflags>-D__arm__
<compileflags>-D_REENTRANT
;
注意調整 ANDROID_NDK 的路徑,這裏使用android-ndk-r11c
,所以用的是android4.9./b2.exe --with-system --with-serialization toolset=gcc-android4.9 link=static runtime-link=static target-os=linux --stagedir=android
--with-system --with-serialization 爲指定要編譯的庫,不指定則默認編譯所有庫
LOCAL_PATH:= $(call my-dir)
#LOCAL_CPPFLAGS += –fexceptions
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_serialization
LOCAL_SRC_FILES:= android/lib/libboost_serialization.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_wserialization
LOCAL_SRC_FILES:= android/lib/libboost_wserialization.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
3. 項目打包
打開jni/Android.mk 添加
LOCAL_WHOLE_STATIC_LIBRARIES += boost_system
LOCAL_WHOLE_STATIC_LIBRARIES += boost_serialization
$(call import-module, boost_1_64_0)
編譯報錯:
則要在 jni/Application.mk 文件中添加 ,
APP_CPPFLAGS += -fexceptions (添加異常支持 LOCAL_CPPFLAGS += –fexceptions)
編譯到boost::serialization報錯,
這類沒定義的函數是c庫,NDK沒實現類些函數。。。boost庫官網說相信你自己能夠實現,好厲害啊~
在cpp文件里加入代碼,替代那些沒定義的函數
#ifdef ANDROID
int wctomb(char *s, wchar_t wc) { return wcrtomb(s,wc,NULL); }
int mbtowc(wchar_t *pwc, const char *s, size_t n) { return mbrtowc(pwc, s, n, NULL); }
#endif