[Android NDK]Toolchains of LLVM and GCC
Keywords: Android NDK Toolchains
LLVM is an umbrela project now, and it contains multiple modular and reusable compiler and toolchain technologies. You can check more details at The LLVM Compiler Infrastructure.
For Android NDK, llvm became the default toolchain since r13b and gcc was removed since r18b.
According to toolchains directory toolchains/llvm/prebuilt/darwin-x86_64
, llvm supports all the ABIs, i.e. x86, x86_64, arm, arm64.
Probably there will be only one llvm
directory under toolchains
directory in future NDK releases when all the gcc related tools, headers and libs are completely ported to llvm.
Updates
Just did a quick test on different NDK revisions to check the configurations for --gcc-toolchain
and --sysroot
which are for cross compilation.
On r16b
--target=armv7-none-linux-androideabi
--gcc-toolchain=~/ndks/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
--sysroot=~/ndks/android-ndk-r16b/sysroot
On r17c
--target=armv7-none-linux-androideabi
--gcc-toolchain=~/ndks/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
--sysroot=~/ndks/android-ndk-r17c/sysroot
On r18b
--target=armv7-none-linux-androideabi19
--gcc-toolchain=~/ndks/android-ndk-r18b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
--sysroot=~/ndks/android-ndk-r18b/sysroot
On r19b
--target=armv7-none-linux-androideabi19
--gcc-toolchain=~/ndks/android-ndk-r19b/toolchains/llvm/prebuilt/darwin-x86_64
--sysroot=~/ndks/android-ndk-r19b/toolchains/llvm/prebuilt/darwin-x86_64/sysroot
As seen above, before NDK r19b, NDK uses clang compiler but the --gcc-toolchain
and --sysroot
are configured as the older paths for build tools, headers and libs.
But, since NDK r19b, the --gcc-toolchain
and --sysroot
are configured as the new tool chains llvm, i.e. toolchains/llvm/prebuilt/darwin-x86_64
, and the tools (e.g. ranlib, ar, strip, etc) header files and libraries of “llvm version” will be used.
Also, note that toolchains/llvm/prebuilt/darwin-x86_64
contains the support for all the Android ABIs, i.e. aarch64-linux-android
for arm64-v8a, arm-linux-androideabi
for armeabi-v7a, i686-linux-android
for x86, x86_64-linux-android
for x86_64.
So, you can try out the NDK r19b if you want to purely use llvm toolchains.
Reference
Android NDK path variable for “strip” command in CMake build tool chain
https://stackoverflow.com/questions/53409479/android-ndk-path-variable-for-strip-command-in-cmake-build-tool-chain
How to set build environment variables to use Clang as part of NDK?
https://stackoverflow.com/questions/36075502/how-to-set-build-environment-variables-to-use-clang-as-part-of-ndk
尽管好几十万人聚居在一小块地方,竭力把土地糟蹋得面目全非,尽管他们肆意把石头砸进地里,不让花草树木生长,尽管他们除尽刚出土的小草,把煤炭和石油烧得烟雾腾腾,尽管他们滥伐树木,驱逐鸟兽,在城市里,春天毕竟还是春天。──列夫·尼古拉耶维奇·托尔斯泰《复活》