简体   繁体   English

Android Studio Cmake:“C 编译器 clang 无法编译一个简单的测试程序。

[英]Android Studio Cmake: "The C compiler clang.exe is not able to compile a simple test program

64 bit Windows 10. Android Studio 2.3.3. 64 位 Windows 10. Android Studio 2.3.3。

I'm trying to use JNI to link an existing C++ project to Android Studio.我正在尝试使用 JNI 将现有的 C++ 项目链接到 Android Studio。 I've also tried to load all of the provided NDK-JNI sample projects.我还尝试加载所有提供的 NDK-JNI 示例项目。 Everything with JNI/Cmake is unable to Gradle Sync, failing with the same error:使用 JNI/Cmake 的所有内容都无法 Gradle 同步,失败并出现相同的错误:

Build command failed.
Error while executing process C:\Users\Alex\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\cmake.exe with arguments {-HC:\Users\Alex\Desktop\android-ndk\hello-jni\app\src\main\cpp -BC:\Users\Alex\Desktop\android-ndk\hello-jni\app\.externalNativeBuild\cmake\armDebug\armeabi -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi -DANDROID_NDK=C:\Users\Alex\AppData\Local\Android\Sdk\ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Alex\Desktop\android-ndk\hello-jni\app\build\intermediates\cmake\arm\debug\obj\armeabi -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:\Users\Alex\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\Users\Alex\AppData\Local\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DANDROID_PLATFORM=android-23 -DANDROID_TOOLCHAIN=clang}
-- Check for working C compiler: C:/Users/Alex/AppData/Local/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: C:/Users/Alex/AppData/Local/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- broken
CMake Error at C:/Users/Alex/AppData/Local/Android/sdk/cmake/3.6.3155560/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler
"C:/Users/Alex/AppData/Local/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/Alex/Desktop/android-ndk/hello-jni/app/.externalNativeBuild/cmake/armDebug/armeabi/CMakeFiles/CMakeTmp
Run Build
Command:"C:\Users\Alex\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\ninja.exe"
"cmTC_accda"
[1/2] Building C object CMakeFiles/cmTC_accda.dir/testCCompiler.c.o
[2/2] Linking C executable cmTC_accda
FAILED: cmd.exe /C "cd .  &&
C:\Users\Alex\AppData\Local\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe
--target=armv5te-none-linux-androideabi
--gcc-toolchain=C:/Users/Alex/AppData/Local/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64
--sysroot=C:/Users/Alex/AppData/Local/Android/sdk/ndk-bundle/sysroot
-isystem
C:/Users/Alex/AppData/Local/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi
-D__ANDROID_API__=23 -g -DANDROID -ffunction-sections -funwind-tables
-fstack-protector-strong -no-canonical-prefixes -march=armv5te
-Werror=format-security -Wl,--exclude-libs,libgcc.a --sysroot
C:/Users/Alex/AppData/Local/Android/sdk/ndk-bundle/platforms/android-23/arch-arm64
-Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings
-Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro
-Wl,-z,now -Wl,--gc-sections -Wl,-z,nocopyreloc -pie -fPIE
CMakeFiles/cmTC_f48b1.dir/testCCompiler.c.o -o cmTC_f48b1 -lm && cd ."
The system cannot find the path specified.
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.

I have all necessary SDK tools installed.我已经安装了所有必要的 SDK 工具。 I've tried using GCC instead of clang.我尝试使用 GCC 而不是 clang。 Thanks for your help!谢谢你的帮助!

The main error message is:主要的错误信息是:

The system cannot find the path specified.

Note that above some places use / as path separator:请注意,上面有些地方使用/作为路径分隔符:

"C:/Users/Alex/AppData/Local/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe"

and have run successfully.并已成功运行。 And this line:而这一行:

C:\Users\Alex\AppData\Local\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe

Seems to have failed.好像失败了。 I guess the problem is the \\ .我想问题是\\ Try find where this path is defined, maybe in the IDE options, configuration files or Makefiles, then modify it may solve the problem.试着找到这个路径是在哪里定义的,可能在IDE选项、配置文件或Makefiles中,然后修改它可能会解决问题。

Its because of clang version mismatch check clang version you have and what minimum clang version Android Application needed!这是因为 clang 版本不匹配检查 clang 版本以及最低 clang 版本 ZE84E30B9390CDB664DB6DB2C9AB878 应用程序需要!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM