Android NDK --gcc-toolchain issue with Clang

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Android NDK --gcc-toolchain issue with Clang

Stephen White
Hi there,

Apologies in advance if this is not the correct mailing list.

I'm working on a C++ project which has existing CMake files and works on Linux and Mac. I was attempting to build it on the Android NDK cross-compiling to ARM64, and ran into an issue.

In particular, the toolchain determination for test compilation fails as follows:

    $HOME/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=aarch64-none-linux-android --gcc-toolchain=$HOME/Android/Sdk/ndk-bundle/toolchains//prebuilt/linux-x86_64 --sysroot=$HOME/Android/Sdk/ndk-bundle/platforms/android-28/arch-arm64 -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=28 -fexceptions  -g  -fPIE -pie -Wl,--gc-sections  CMakeFiles/cmTC_34db0.dir/testCCompiler.c.o  -o cmTC_34db0 
    /usr/bin/ld: unrecognised emulation mode: aarch64linux

The problem seems to be where --gcc-toolchain is set to:


(note the double slash).

On my installation of the NDK (r19c, Linux), the toolchain seems to be in:


My android.toolchain.cmake file is as follows:


set(CMAKE_ANDROID_NDK $ENV{HOME}/Android/Sdk/ndk-bundle)



set(CMAKE_ANDROID_STL_TYPE c++_shared)

I was able to get it to work by applying the small patch below:

diff --git a/Modules/Platform/Android/Determine-Compiler-NDK.cmake b/Modules/Platform/Android/Determine-Compiler-NDK.cmake

index 5f2cc524e5..c211bbceee 100644

--- a/Modules/Platform/Android/Determine-Compiler-NDK.cmake

+++ b/Modules/Platform/Android/Determine-Compiler-NDK.cmake



   message(STATUS "Android: Selected Clang toolchain '${_ANDROID_TOOL_CLANG_NAME}' with GCC toolchain '${_ANDROID_TOOL_NAME}'")







The reason seems to be that if ANDROID_TOOL_NAME contains -clang, it is set to the empty string on line 120 (CMake 10.13), so the external toolchain path contains an empty directory element (//). ANDROID_TOOL_LLVM_NAME contains "llvm", which is the correct string to make the above path correct on my installation.

If I'm doing something wrong and there's a better way to do this which doesn't require patching CMake, please let me know.




Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: