Windows 和 android 平台Boost编译方法

xiaoxiao2021-02-28  107

1.Windows 平台编译

环境

Windows 10 Visual Studio 2015  boost 1.64

步骤

直接执行 bootstrap.bat 之后直接运行 bjam.exe,或者指定编译命令 指定msvc版本14.0对应的是vs2015--stagedir是指定编译后存放的目录 ./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 指定不编译的库 等待库编译.... 编译好后在VS中设置包含目录和库目录即可

2.Android 平台编译

1.下载安装Cygwin

下载Cygwin (http://www.cygwin.com/) 

安装时,默认设置,只选择Devel,将后面的Default改为Install,然后就是等了。

安装完后,进入Cygwin的终端,分别 gcc -v 和 make -v 查看版本 配置环境变量,添加环境变量 NDK_ROOT= E:/Android/android-ndk-r11c 2.NDK编译boost生成静态库 解压 boost_1_64_0.zip 到 E:\Android\android-ndk-r11c\sources 文件夹里 进入boost_1_64_0目录运行 bootstrap.sh 生成 b2 进入 boost_1_64_0/project-config.jam,增加下面内容 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 编译 boost,在 boost_1_64_0/android/lib 下生成静态库  ./b2.exe --with-system --with-serialization toolset=gcc-android4.9 link=static runtime-link=static target-os=linux --stagedir=android --with-system --with-serialization 为指定要编译的库,不指定则默认编译所有库 在boost_1_64_0 文件夹下新建 Android.mk 写入  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报错,

参考http://stackoverflow.com/questions/15479136/how-to-implement-mbtowc-for-android-or-ideally-how-not-to

这类没定义的函数是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
转载请注明原文地址: https://www.6miu.com/read-52496.html

最新回复(0)