no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | blog:2017:0925_build_boost_for_android [2021/09/02 13:39] (current) – Discussion status changed manu | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Building Boost libraries for Android platform ====== | ||
+ | |||
+ | {{tag> | ||
+ | |||
+ | For my personal project **NervSeed** I would like to be able to compile advanced c++ code for Android. So I was thinking: at some point I will need the boost libraries, so i might just as well try to figure out right now how to build boost for Android. Afterall, this is a good timing since I've just setup the required support in this project to support compilation for: linux64, win32, win64, msvc32 and msvc64 => we might just as well try to add android to the list now :-) | ||
+ | |||
+ | ====== ====== | ||
+ | |||
+ | ====== Investigations ====== | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | ====== Implementing support for compilation from windows ====== | ||
+ | |||
+ | It seems the easiest option is to start with creating a dedicated toolchain from the NDK tools. | ||
+ | |||
+ | ===== Creating Standalone NDK toolchain ===== | ||
+ | |||
+ | Trying to execute a simple script to build the standalone toolchain: <sxh bash> | ||
+ | { | ||
+ | local ndkdir=" | ||
+ | echo "Using NDK folder: $ndkdir" | ||
+ | |||
+ | # Select destination folder: | ||
+ | local destdir=" | ||
+ | |||
+ | # call the make toolchain script: | ||
+ | $ndkdir/ | ||
+ | |||
+ | echo "Done installing NDK toolchain for API 21" | ||
+ | }</ | ||
+ | |||
+ | But we get an error when running this from cygwin: < | ||
+ | Using NDK folder: / | ||
+ | Unsupported platform: CYGWIN_NT-10.0 | ||
+ | Done installing NDK toolchain for API 21 | ||
+ | </ | ||
+ | |||
+ | => Let's try using the make-standalone-toolchain.sh script instead: results are a little bit better... But now we have a message stating that this script will be removed in r13 anyway: < | ||
+ | Using NDK folder: / | ||
+ | WARNING: make-standalone-toolchain.sh will be removed in r13. Please try make_standalone_toolchain.py now to make sure it works for your needs. | ||
+ | HOST_OS=cygwin | ||
+ | HOST_EXE=.exe | ||
+ | HOST_ARCH=x86_64 | ||
+ | HOST_TAG=windows-x86_64 | ||
+ | HOST_NUM_CPUS=8 | ||
+ | BUILD_NUM_CPUS=16 | ||
+ | ERROR: Option ' | ||
+ | Done installing NDK toolchain for API 21</ | ||
+ | |||
+ | => So, not so much choice: we have to get ourself a decent portable python installation. Just retrieving a zip package of the python version available from chromium depot tools! :-) | ||
+ | |||
+ | < | ||
+ | |||
+ | **Note**: could check the following page to [[https:// | ||
+ | |||
+ | => **OK**: Can now build the toolchain without error with the portable python installation. | ||
+ | |||
+ | ===== Preparing script for boost compilation ===== | ||
+ | |||
+ | Tried the simple clang toolchain usage, getting this error: < | ||
+ | local PREVPATH=" | ||
+ | local chaindir=" | ||
+ | echo "Using NDK toolchain path: $chaindir" | ||
+ | export PATH=" | ||
+ | |||
+ | ./ | ||
+ | |||
+ | Tried a bit more complex script with: <sxh bash> | ||
+ | ./ | ||
+ | |||
+ | local chaindir=" | ||
+ | echo "Using NDK toolchain path: $chaindir" | ||
+ | |||
+ | echo "using clang : android : $chaindir/ | ||
+ | |||
+ | # cxxflags=" | ||
+ | ./b2 --prefix=" | ||
+ | include=$chaindir/ | ||
+ | runtime-link=static | ||
+ | </ | ||
+ | |||
+ | Checking this script file it seems we are using CRLF lien endings, which might not be appropriate. So let's fix that by creating our own launcher: | ||
+ | |||
+ | <sxh bash> | ||
+ | #!/bin/bash | ||
+ | if [ " | ||
+ | $chaindir/ | ||
+ | else | ||
+ | # target/ | ||
+ | $chaindir/ | ||
+ | fi | ||
+ | EOF | ||
+ | chmod +x nvclang | ||
+ | |||
+ | |||
+ | echo "using clang : android : $PWD/ | ||
+ | |||
+ | => With this change the compilation seems to be going smoothly :-) (crossing fingers...) => Nope... Still no static libraries built:, during compilation we now get errors such as: < | ||
+ | In file included from .\boost/ | ||
+ | In file included from .\boost/ | ||
+ | .\boost/ | ||
+ | # include < | ||
+ | ^ | ||
+ | 1 error generated.</ | ||
+ | |||
+ | Now trying the enhanced user-config version: **OK, this works!** | ||
+ | |||
+ | ====== Implementing support for compilation from linux ====== | ||
+ | |||
+ | Updated the build scripts to: | ||
+ | - Create a standalone toolchain in **tools/ | ||
+ | - Build boost from this toolchain (based on **android-ndk-r15c**) | ||
+ | |||
+ | => This doesn' | ||
+ | |||
+ | One of our goal is to be able to build android libraries for use in Unreal Engine 4, and thus we should stick with the compilations capabilities available in Codeworks-1R6, | ||
+ | |||
+ | Downloading proper NDK version: <sxh bash>cd / | ||
+ | wget https:// | ||
+ | |||
+ | => **OK** with this version of the android NDK we can build the boost libraries the same way as on windows. Now one thing I just noticed is that on linux we seem to get some support for C++11 features: < | ||
+ | - lockfree boost:: | ||
+ | - Boost.Config Feature Check: cxx11_auto_declarations : yes | ||
+ | - Boost.Config Feature Check: cxx11_constexpr : yes | ||
+ | - Boost.Config Feature Check: cxx11_defaulted_functions : yes | ||
+ | - Boost.Config Feature Check: cxx11_final : yes | ||
+ | - Boost.Config Feature Check: cxx11_hdr_mutex : no | ||
+ | - Boost.Config Feature Check: cxx11_hdr_tuple : yes | ||
+ | - Boost.Config Feature Check: cxx11_lambdas : yes | ||
+ | - Boost.Config Feature Check: cxx11_noexcept : yes | ||
+ | - Boost.Config Feature Check: cxx11_nullptr : yes | ||
+ | - Boost.Config Feature Check: cxx11_rvalue_references : yes | ||
+ | - Boost.Config Feature Check: cxx11_template_aliases : yes | ||
+ | - Boost.Config Feature Check: cxx11_thread_local : yes | ||
+ | - Boost.Config Feature Check: cxx11_variadic_templates : yes</ | ||
+ | |||
+ | Checking this again from windows: < | ||
+ | - lockfree boost:: | ||
+ | - Boost.Config Feature Check: cxx11_auto_declarations : no | ||
+ | - Boost.Config Feature Check: cxx11_constexpr : no | ||
+ | - Boost.Config Feature Check: cxx11_defaulted_functions : no | ||
+ | - Boost.Config Feature Check: cxx11_final : no | ||
+ | - Boost.Config Feature Check: cxx11_hdr_mutex : no | ||
+ | - Boost.Config Feature Check: cxx11_hdr_tuple : no | ||
+ | - Boost.Config Feature Check: cxx11_lambdas : no | ||
+ | - Boost.Config Feature Check: cxx11_noexcept : no | ||
+ | - Boost.Config Feature Check: cxx11_nullptr : no | ||
+ | - Boost.Config Feature Check: cxx11_rvalue_references : no | ||
+ | - Boost.Config Feature Check: cxx11_template_aliases : no | ||
+ | - Boost.Config Feature Check: cxx11_thread_local : no | ||
+ | - Boost.Config Feature Check: cxx11_variadic_templates : no</ | ||
+ | | ||
+ | Hmmm... that's weird... Checking [[https:// | ||
+ | * Added **cxxflags=" | ||
+ | * Okay, the missing C++11 features above might not be that critical for now (waiting to see what we get when trying to build our projects on android ?) So for now, let's just move forward. | ||
+ | |||
+ | ====== Conclusion ====== | ||
+ | |||
+ | In the end, building boost for android was pretty easy, using mainly the following script commands: <sxh bash> | ||
+ | ./ | ||
+ | |||
+ | # cf. https:// | ||
+ | local chaindir=" | ||
+ | echo "Using NDK toolchain path: $chaindir" | ||
+ | local ndkdir=" | ||
+ | echo "Using NDK root path: $ndkdir" | ||
+ | |||
+ | cat <<EOF >nvclang | ||
+ | #!/bin/bash | ||
+ | if [ " | ||
+ | $chaindir/ | ||
+ | else | ||
+ | # target/ | ||
+ | $chaindir/ | ||
+ | fi | ||
+ | EOF | ||
+ | chmod +x nvclang | ||
+ | |||
+ | # echo "using clang : android : $PWD/ | ||
+ | # echo "using clang : android : $chaindir/ | ||
+ | |||
+ | cat <<EOF > | ||
+ | import os ; | ||
+ | local AndroidNDKRoot = `nv_to_win_path $ndkdir` ; | ||
+ | using clang : android | ||
+ | : | ||
+ | $PWD/ | ||
+ | : | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | #< | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | ; | ||
+ | EOF | ||
+ | |||
+ | ./b2 --prefix=" | ||
+ | --without-mpi --without-python variant=release threading=multi threadapi=pthread link=static \ | ||
+ | runtime-link=static | ||
+ | |||
+ | We might not need all the compileflags provided above in the user-config.jam file, but I didn't try to remove them anyway :-). | ||
+ | |||
+ | ~~DISCUSSION: | ||