env:
windows xp 32 bit
mingw
official NDK
1. 下載源代碼
地址是 :http://sourceforge.net/projects/boost/files/boost/1.54.0/
本文下載的是 boost_1_54_0.7z
2. 解壓源代碼到任意目錄
本問解壓后匹配文件: ***/boost154/tools/build/v2/user-config.jam
3. 生成bjam.exe
打開cmd.exe
切換目錄至 ***/boost154/
輸入命令: bootstrap.bat 回車
E:\boost\boost_1_54_0>bootstrap.bat
這樣在***/boost154下生成 bjam.exe 和 b2.exe
4. 修改bjam配置文件user-config.jam
配置文件路徑 ***/boost154/tools/build/v2/user-config.jam
解壓后此文件是全部注釋的說明文件
仿照其他博文 在最后加上如下注釋內的內容
import os ; if [ os.name ] = CYGWIN || [ os.name ] = NT { androidPlatform = windows ; } 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/android-ndk-r8e ; using gcc : android4.6 : $(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-g++ : <archiver>$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ar <ranlib>$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ranlib <compileflags>--sysroot=$(ANDROID_NDK)/platforms/android-9/arch-arm <compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.6/include <compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include <compileflags>-DNDEBUG <compileflags>-D__GLIBC__ <compileflags>-DBOOST_FILESYSTEM_VERSION=3 <compileflags>-lstdc++ <compileflags>-lgnustl_shared <compileflags>-mthumb <compileflags>-fno-strict-aliasing <compileflags>-std=gnu++11 <compileflags>-O2 ;
注意:
ANDROID_NDK 為NDK跟目錄,匹配文件如: ../../android/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include
這段配置比較微妙,最好復制后進行修改,開始自己寫的時候不知道哪里錯了,一直提示 大寫 Error android4.6 一類的錯誤,無法開始編譯
5. MinGW中輸入bjam編譯命令
打開mingw命令端口,切換至 ***/boost154/
輸入如下注釋中的命令,並回車
$ bjam --without-python toolset=gcc-android4.6 link=static runtime-link=static target-os=linux --stagedir=android
注意:
--stagedir
指定編譯后庫的存放目錄,命令輸入時的當前路徑,
本文是 ***/boost154/android ,結果保存在 ***/boost154/android/lib 中
--without-python
不編譯python庫,
使用 --without-***屏蔽庫
庫列表可以是
atomic
chrono
context
coroutine
date_time
exception
filesystem
graph
graph_parallel
iostreams
locale
log
math
mpi
program_options
python
random
regex
serialization
signals
system
test
thread
timer
wave
命令回車后首先會輸出當前配置
Building the Boost C++ Libraries. Performing configuration checks - 32-bit : yes (cached) - arm : yes (cached) - has_icu builds : no (cached) warning: Graph library does not contain MPI-based parallel componen note: to enable them, add "using mpi ;" to your user-config.jam - zlib : no (cached) - iconv (libc) : no (cached) - iconv (separate) : no (cached) - icu : no (cached) - icu (lib64) : no (cached) - Boost.Locale needs either iconv or ICU library to be built. - Boost.Locale needs either iconv or ICU library to be built. - Boost.Locale needs either iconv or ICU library to be built. - Boost.Locale needs either iconv or ICU library to be built. - Boost.Locale needs either iconv or ICU library to be built. - Boost.Locale needs either iconv or ICU library to be built. - x86 : no (cached) - gcc visibility : yes (cached) - long double support : yes (cached) warning: skipping optional Message Passing Interface (MPI) library. note: to enable MPI support, add "using mpi ;" to user-config.jam. note: to suppress this message, pass "--without-mpi" to bjam. note: otherwise, you can safely ignore this message. Component configuration: - atomic : building - chrono : building - context : building - coroutine : building - date_time : building - exception : building - filesystem : building - graph : building - graph_parallel : building - iostreams : building - locale : building - log : building - math : building - mpi : building - program_options : building - python : not building - random : building - regex : building - serialization : building - signals : building - system : building - test : building - thread : building - timer : building - wave : building
編譯結束后輸出
...failed updating 5 targets... ...skipped 12 targets... ...updated 51 targets...
與官方下載庫比較, ***/boost154/android/lib/中的庫,沒有生成有
context
filesystem
locale
log
python(輸入命令時設置不編譯,可能需要第三方庫
thread
zlib
下面的博文寫NDK不支持wide chars,但是wserialization 、serialization都生成了.
6.參考
本文方法主要參考
http://www.codexperiments.com/android/2011/05/tips-tricks-building-boost-with-ndk-r5/
這篇播放寫NDK不支持wide chars,並且 CrystaX官網也寫NDK不支持wide chars,
boost-for-android 補丁工程
https://github.com/MysticTreeGames/Boost-for-Android/archive/master.zip
提供補丁修改boost代碼,貌似能解決上面編譯不過的庫
提供批處理和bjam配置文件...不會用......
CrystaX官方
http://www.crystax.net/en/android/ndk?format=php
boost郵件關於android/ios的問答
http://lists.boost.org/Archives/boost/2012/12/199676.php
幾個編譯筆記
http://www.cppblog.com/sunicdavy/archive/2013/07/20/201993.html
http://blog.sina.com.cn/s/blog_a6946c8a01016aot.html
----------------------2013-09-18---11:43:13
重新編譯,均使用MinGW
1.Mingw編譯bjam.exe
Mingw終端切換至
boost_1_53_0\tools\build\v2\engine 目錄 執行
$ build.sh
等到提示:
[COMPILE] bin.ntx86\b2.exe
[COPY] bin.ntx86\bjam.exe
...updated 2 targets...
將 boost_1_53_0\tools\build\v2\engine\bin.ntx86 目錄下的bjam.exe拷貝到 boost_1_53_0 目錄下
2.修改bjam配置文件
boost_1_53_0\tools\build\v2\user-config.jam
import os ; if [ os.name ] = CYGWIN || [ os.name ] = NT { androidPlatform = windows ; } else if [ os.name ] = LINUX { androidPlatform = linux-x86_64 ; } else if [ os.name ] = MACOSX { androidPlatform = darwin-x86 ; } modules.poke : NO_BZIP2 : 1 ; ANDROID_NDK = ../../code_other/android/android-ndk-r8e ; using gcc : android4.6 : $(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-g++ : <archiver>$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ar <ranlib>$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ranlib <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-ffunction-sections <compileflags>-funwind-tables <compileflags>-D__ARM_ARCH_5__ <compileflags>-D__ARM_ARCH_5T__ <compileflags>-D__ARM_ARCH_5E__ <compileflags>-D__ARM_ARCH_5TE__ <compileflags>-Wno-psabi <compileflags>-march=armv5te <compileflags>-mtune=xscale <compileflags>-msoft-float <compileflags>-mthumb <compileflags>-Os <compileflags>-fomit-frame-pointer <compileflags>-fno-strict-aliasing <compileflags>-finline-limit=64 <compileflags>-I$(ANDROID_NDK)/platforms/android-9/arch-arm/usr/include <compileflags>-Wa,--noexecstack <compileflags>-DANDROID <compileflags>-D__ANDROID__ <compileflags>-DNDEBUG <compileflags>-O2 <compileflags>-g <compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.6/include <compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include ;
需要跟上 ranlib 這個標簽,否則會顯示 archiver
'"..\..\code_other\android\android-ndk-r8e\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\bin"' 不是內部或外部命令,
也不是可運行的程序或批處理文件。不理解,gcc 能找到,ar找不到.
3.打補丁
將https://github.com/MysticTreeGames/Boost-for-Android 提供的1.53的補丁拷貝至 boost_1_53_0\MinGW終端切換至 boost_1_53_0 的父目錄,執行
$ patch -Np1 -d boost_1_53_0 < boost_1_53_0/boost-1_53_0.patch
會輸出:
patching file boost/asio/detail/socket_types.hpp Hunk #1 succeeded at 124 (offset 1 line). patching file boost/asio/ip/impl/address_v6.ipp patching file boost/config/user.hpp patching file boost/detail/endian.hpp patching file boost/interprocess/detail/workaround.hpp patching file libs/filesystem/src/operations.cpp patching file tools/build/v2/tools/android.jam patching file tools/build/v2/tools/android.py
4.編譯
MinGW切換至目錄 boost_1_53_0,執行
$ bjam --without-python toolset=gcc-android4.6 link=static runtime-link=static target-os=linux --stagedir=android_static
libboost_thread-gcc-mt-s-1_53.a庫無法生成.還是提示: libs\thread\src\win32\thread.cpp:31:21: fatal error: process.h: No such file or directory
libboost_context-gcc-mt-s-1_53.a沒有生成,'armasm' 不是內部或外部命令,也不是可運行的程序