Skip to content

CMake incompatible with Android NDK r16 clang toolchain

When trying to build an Android project with NDK r16 beta 1 and the clang toolchain, the toolchain's paths are broken. This is a regression from the current stable release NDK r15c. It works when using the default GCC toolchain (which is deprecated in NDK and will be removed).

Here's a minimal example:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.9)
project(CMakeAndroidTest)
add_executable(cmake-android-test main.cpp)

main.cpp:

int main() {
    return 0;
}

The following was run with CMake 3.9.1 on Linux x86_64 (Fedora 26).

NDK r15c, default GCC toolchain: works

$ ANDROID_NDK=/path/to/ndk-r15c cmake .. -DCMAKE_SYSTEM_NAME=Android
-- Android: Targeting API '26' with architecture 'arm', ABI 'armeabi', and processor 'armv5te'
-- Android: Selected GCC toolchain 'arm-linux-androideabi-4.9'
[...]
-- Build files have been written to: [...]

NDK r15c, clang toolchain: works

$ ANDROID_NDK=/path/to/ndk-r15c cmake .. -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang
-- Android: Targeting API '26' with architecture 'arm', ABI 'armeabi', and processor 'armv5te'
-- Android: Selected Clang toolchain 'arm-linux-androideabi-clang' with GCC toolchain 'arm-linux-androideabi-4.9'
[...]
-- Build files have been written to: [...]

NDK r16 beta 1, default GCC toolchain: works

$ ANDROID_NDK=/path/to/ndk-r16-beta1 cmake .. -DCMAKE_SYSTEM_NAME=Android
-- Android: Targeting API '26' with architecture 'arm', ABI 'armeabi', and processor 'armv5te'
-- Android: Selected GCC toolchain 'arm-linux-androideabi-4.9'
[...]
-- Build files have been written to: [...]

NDK r16 beta 1, clang toolchain: fails

$ ANDROID_NDK=/path/to/ndk-r16-beta1 cmake .. -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang
-- Android: Targeting API '26' with architecture 'arm', ABI 'armeabi', and processor 'armv5te'
-- Android: Selected Clang toolchain 'arm-linux-androideabi-clang' with GCC toolchain 'arm-linux-androideabi-4.9'
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
  The CMAKE_C_COMPILER:

    /path/to/ndk-r16-beta1/toolchains//prebuilt/linux-x86_64/bin/clang

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:2 (project):
  The CMAKE_CXX_COMPILER:

    /path/to/ndk-r16-beta1/toolchains//prebuilt/linux-x86_64/bin/clang++

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

The correct path where clang and clang++ are located is /path/to/ndk-r16-beta1/toolchains/llvm/prebuilt/linux-x86_64/bin. Notice the missing llvm in the path used by CMake.

Edited by Ghost User
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information