Windows 和 android 平台Boost编译方法
来源:互联网 发布:03年搞笑网络歌曲 编辑:程序博客网 时间:2024/05/17 03:53
1.Windows 平台编译
环境
Windows 10
Visual Studio 2015
boost 1.64
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 += –fexceptionsinclude $(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_serializationLOCAL_SRC_FILES:= android/lib/libboost_serialization.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= boost_wserializationLOCAL_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 ANDROIDint 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
阅读全文
0 0
- Windows 和 android 平台Boost编译方法
- boost编译(windows平台)
- boost全平台编译方法
- boost多平台编译方法
- Boost全平台编译方法
- 编译boost到Android平台
- Boost-Windows安装和编译
- Win32平台Boost的编译方法
- Linux平台Boost的编译方法
- Linux平台Boost的编译方法
- Win32 平台 Boost 的编译方法
- Linux平台Boost的编译方法
- Linux平台Boost的编译方法
- Linux平台Boost的编译方法
- Linux平台Boost的编译方法
- Linux平台Boost的编译方法
- Boost - windows下编译boost和提取boost子集
- sqlcipher windows 平台编译方法
- 再读《重构-改善既有代码的设计》
- jzoj1274. 游历的路线
- SSD(固态硬盘)编程
- android开发 -TabHost控件
- 面试云计算岗位时最常遇到的40个问题
- Windows 和 android 平台Boost编译方法
- LinkedList
- ubuntu16.04编译boost for Android
- Javascript创建对象
- Websocket原理
- HDOJ 2093 考试排名(表格,字符串)
- C#中的委托、lamba与Func Action的使用
- C语言IO操作
- Java的主要就业方向