Awww the lovely boost… awww the lovely NDK… They are separately really affectionate. But NOT TOGETHER.

Well, now they are, it’s just a matter of them getting to know eachother. Once you set up the right environment (a romantic candlelight dinner) and they spend some time together, they’ll be a happy couple. And you will be happy with the results too.

But how do we reach this stage of harmony? Let me tell you: it’s not straightforward to compile boost for Android under Windows, especially when taking into account that we can target different platforms (such as ARM and Intel devices). I’ve literally lost two days doing this as there was very little information about it in the internet. My objective here is to prevent you from wasting another two days of your life; you’re not alone in this matter. I might even come back to my own blog entry in the future if I am to recompile it (I prey not to).

So, how to compile it?

Let’s get down to business:

Download Boost 1.56. Extract it in c:\boost156, for instance Download NDK r9d. You may use a newer version if you adapt this guide. Use your command line (or something better) and go to the boost extracted directory. Type bootstrap.bat It should do some stuff and create a bunch of files. You should edit project-config.jam with the following: import option ; using gcc : intel : i686-linux-android-g++.exe ; using gcc : arm : arm-linux-androideabi-g++.exe ; option.set keep-going : false ; Add to your PATH variables the following locations: C:\DevTools\android-ndk-r9d\toolchains\x86-4.8\prebuilt\windows\bin;C:\DevTools\android-ndk-r9d\toolchains\arm-linux-androideabi-4.8\prebuilt\windows\bin Add this batch script arm_build.bat in the root of your boost directory: rmdir bin.v2\libs /s /q rmdir stage\lib /s /q b2 link=static threading=multi threadapi=pthread target-os=android ^ toolset=gcc-arm ^ --without-context --without-coroutine --without-thread --without-log ^ --without-test --without-atomic --without-chrono --without-filesystem ^ --without-graph --without-graph_parallel --without-math --without-python --without-random ^ --without-signals --without-wave --without-timer --without-mpi ^ --without-program_options --without-container --without-iostreams --without-locale ^ define=BOOST_MATH_DISABLE_FLOAT128 ^ include=C:\DevTools\android-ndk-r9d\sources\cxx-stl\gnu-libstdc++\4.8\include ^ include=C:\DevTools\android-ndk-r9d\sources\cxx-stl\gnu-libstdc++\4.8\libs\armeabi\include ^ include=C:\DevTools\android-ndk-r9d\platforms\android-19\arch-x86\usr\include set ARPATH=C:\DevTools\android-ndk-r9d\toolchains\arm-linux-androideabi-4.8\prebuilt\windows\bin\arm-linux-androideabi-ar.exe set OUT_TMP_DIR=out_tmp_arm set OUTLIB=libboost_armeabi.a rmdir %OUT_TMP_DIR% /s /q mkdir %OUT_TMP_DIR% cd %OUT_TMP_DIR% FOR %%f in (..\stage\lib\*) DO %ARPATH% xv %%f cd .. %ARPATH% qv %OUTLIB% %OUT_TMP_DIR%\*.o If you want to compile for intel as well, just copy the script and change a few lines: toolset=gcc-intel ^ set ARPATH=C:\DevTools\android-ndk-r9d\toolchains\x86-4.8\prebuilt\windows\bin\i686-linux-android-ar.exe set OUT_TMP_DIR=out_tmp_intel set OUTLIB=libboost_x86.a

The script I provide will also join all per-package-libraries into a single static library for its easier use. Surely, feel free to adapt the script with your needs, as you might have different paths, a different NDK version and you might actually want to compile other packages as well (just remove –without-XXX).

Let me know if it worked (or not) for you. I’ll try my best to lend you a hand if you run into troubles.

EDIT: Ian posted a link to his own compiled version of boost 1.53. I didn’t try them, but in case they help someone, check his comment.