-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake toolchain file doesn't support building with clang in r16 beta 1 #504
Comments
This has been fixed (and works for me) with 16.0.4293906 rc1. Albeit I tried with Android Studio version of CMake - 3.6.4111459. |
It has not been fixed yet. We both used the same build. When you use CMake 3.6.x or below, the issue doesn't occur because CMake's built-in Android support was only added in 3.7. The issue is that CMake's Android support and the NDK 16's toolchain file don't work together properly. |
This will be fixed in CMake 3.9.2: https://gitlab.kitware.com/cmake/cmake/merge_requests/1237 If nothing is done on the NDK side, NDK 16 won't work with CMake 3.7 to 3.9.1. This is fine by me, but should be decided by the NDK maintainers. |
In theory https://android-review.googlesource.com/c/platform/ndk/+/485299 protects us from all the cmake version incompatibilities. Longer term we'll be exporting most of the tables CMake cares about so the two stop fighting each other, but this works as a stopgap. |
I feel compelled to point out that this causes failures in simple "Hello World" projects out of the box. These sort of experiences are exactly why I've aborted using five different installs, over the years, of Android Studio, always waiting for a high enough minor version that things were stable-- only to never see things quite get there, but instead to see a major version bump, and all of the instability naturally associated with X.0.[0,1]. I keep wondering if Android Studio is ever going to be a project that knows how to push the release until ALL of the "simple" new project cases actually build. |
In any case, steps to reproduce for Hello World are:
Error:(61, 0) The C compiler "/home/mheck/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" is not able to compile a simple test program. |
Trivial cases are not broken. We have tests that show they work. If you're experiencing the problem discussed in this bug, you're not using the out of the box experience. Studio provides its own version of CMake (a version of 3.6 with a few modifications to better support IDE functionality) and uses the CMake toolchain file shipped with the NDK. This bug is regarding using a CMake other than the one that was shipped with Studio. Are you using NDK r16? If not, you don't have the fix for this. If you are, please file a bug against Studio (http://b.android.com). As I've said, our test cases show no issues here, so if the hello world use case is broken it may be that studio is using the NDK incorrectly. |
@DanAlbert I am facing similar kind of problem but its with r17 of ndk . I am just creating simple hello world project using C++ support using android stuido as @hpg-mheck done. After building of project gives me below error. Caused by: org.gradle.internal.UncheckedException: Build command failed. Error while executing process D:\Android_Studio\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\Android_Studio\Workspace\NDKTestSample\app.externalNativeBuild\cmake\debug\x86 --target native-lib} [1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o FAILED: D:\Android_Studio\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=i686-none-linux-android --gcc-toolchain=D:/Android_Studio/sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/windows-x86_64 --sysroot=D:/Android_Studio/sdk/ndk-bundle/sysroot -Dnative_lib_EXPORTS -isystem D:/Android_Studio/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include -isystem D:/Android_Studio/sdk/ndk-bundle/sources/android/support/include -isystem D:/Android_Studio/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include -isystem D:/Android_Studio/sdk/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=15 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -MF CMakeFiles\native-lib.dir\src\main\cpp\native-lib.cpp.o.d -o CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -c D:\Android_Studio\Workspace\NDKTestSample\app\src\main\cpp\native-lib.cpp error: error reading 'D:\Android_Studio\Workspace\NDKTestSample\app\src\main\cpp\native-lib.cpp' 1 error generated. ninja: build stopped: subcommand failed. NDK Version: 17.1.4828580 |
The CMake toolchain shipped with the NDK doesn't work with CMake-3.7.2 or 3.9.1. To ensure compatibility, use the shipped cmake binary. See android/ndk#254 or https://gitlab.kitware.com/cmake/cmake/issues/16708 as well as android/ndk#504 Change-Id: I31366cd813edc44d0e62021872c63d9fc06ffb7c
Description
When using the android.toolchain.cmake file shipped with NDK r16 beta 1 with the clang compiler, the build fails due to wrong CMAKE_C_COMPILER and CMAKE_CXX_COMPILER paths.
Here's a minimal example, run with CMake 3.9.1:
CMakeLists.txt:
main.cpp:
Notice the missing
llvm
in the path used by CMake.When setting ANDROID_TOOLCHAIN to gcc or downgrading to NDK r15c, the build is fixed. Also, downgrading to CMake 3.6 (which predates the built-in Android support in CMake) fixes the build. The issue also occurs when invoking the built-in Android support of CMake directly, see my bug report at CMake.
Workaround
Change android.toolchain.cmake:
This prevents CMake from using its built-in Android support.
Environment Details
The text was updated successfully, but these errors were encountered: