Boost is commonly used in developing a PC program in C++. But if the target is a mobile platform such as Android? We are working on porting KlayGE to Android in these days. As a dependent library, boost must be ported, too. The official boost doesn’t support Android, So I have to do my own.
Inspired by MysticTreeGames’s Boost-for-Android project, I tried to get boost 1.47 compiled with the latest NDK from Crystax.
Preparation
Some packages must be downloaded
Patches
First of all, the MysticTreeGames’s patch is based on boost 1.45 and official NDK r5. It’s probably not work perfectly on the latest version. Because some source files are changed from 1.45 to 1.47, the patch may failed. So I have to manually modify all places in the original boost 1.47, follow by the patches. It’s not difficult because there are only 12 patches.
Script
MysticTreeGames’s build-android.sh from Boost-for-Android also failed. Probably because it’s not tested well under Cygwin. I wrote a build_android.sh and a build_android.bat for workaround. Fortunately it’s simple and works well on Windows, Cygwin and Linux. (A bonus is that you don’t need the Cygwin any more if using build_android.bat!)
After that, the boost 1.47 can be compiled by NDK r6. The limitation is we can only use “link=static runtime-link=static”.
Build by VC again?
When I tried to use VC10 to rebuild boost for Windows, a problem shows up. The user-config.jam is patched so that it can only work with NDK’s compiler. The solution is move the modified user-config.jam to the root folder of boost, renamed it into some other name, such as user-config-android.jam. Then you can use “bjam –user-config=./user-config-android.jam …” to tell bjam use this .jam file as user config.
All in one
You can find my modified files in the attachment. Before compiling, you need to set an environment variable name “ANDROID_NDK”, which is point to your NDK’s root.
Comments