“C 编译器 [...] 无法编译简单的测试程序"使用 CMake 和 Android NDK

quot;The C Compiler [...] is not able to compile a simple test programquot; using CMake and Android NDK(“C 编译器 [...] 无法编译简单的测试程序使用 CMake 和 Android NDK)

本文介绍了“C 编译器 [...] 无法编译简单的测试程序"使用 CMake 和 Android NDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 Windows 上测试 Visual Studio 2017 RC CMake 对 Android NDK C++ 项目的支持并遇到问题.

I'm currently testing the Visual Studio 2017 RC CMake support for Android NDK C++ projects on Windows and encountered an issue.

当我尝试使用以下命令生成 CMake 缓存时:

When I try to generate the CMake cache with:

<cmake.exe> -G "Visual Studio 15 2017" -DCMAKE_INSTALL_PREFIX:PATH=<install_path> -DCMAKE_TOOLCHAIN_FILE="<androidNDK_path>uildcmakeandroid.toolchain.cmake" -DANDROID_TOOLCHAIN=gcc -DANDROID_ABI="armeabi-v7a with NEON" --DCMAKE_BUILD_TYPE="Debug" <source>

我收到以下错误(如果我不强制 gcc,clang 也会发生同样的情况):

I get the following error (The same happens with clang if I don't force gcc):

The C compiler "<androidNDK_path>/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc.exe" is not able to compile a simple test program.

在此之前,我收到警告说 C 和 CXX 编译器的标识未知,但我不确定这是否相关.

Before that I get the warnings that the identification of the C and CXX compilers are unknown but I'm not sure that's relevant.

我在临时测试项目中遇到了更多错误,但它们似乎没有提供很多信息,例如

I get more errors for the temporary test project but they don't seem to give a lot of information like

C:Program Files (x86)Microsoft Visual
Studio2017EnterpriseCommon7IDEVCVCTargetsMicrosoft.Cpp.Platform.targets(57,5):
error MSB4018: The "VCMessage" task failed unexpectedly.

C:Program Files (x86)Microsoft Visual
Studio2017EnterpriseCommon7IDEVCVCTargetsMicrosoft.Cpp.Platform.targets(57,5):
error MSB4018: System.FormatException: Index (zero based) must be greater
than or equal to zero and less than the size of the argument list.

我该如何解决这个问题?

How could I troubleshoot this?

推荐答案

对于发现这篇文章并遇到相同问题的每个人:问题似乎是 Visual Studio 生成器.此外,Android 工具链似乎需要一个带有make"路径的参数.所以为了解决这两个问题,我安装了 MSYS (http://www.mingw.org/wiki/MSYS) 并将 CMake 命令更改为:

For everybody who finds this post and has the same issue: the problem seems to be the Visual Studio generator. Also it seems like the Android toolchains requires an argument with the path to "make". So to solve both I installed MSYS (http://www.mingw.org/wiki/MSYS) and changed the CMake command to:

<cmake.exe>  -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX:PATH=<install_path> -DCMAKE_TOOLCHAIN_FILE="<androidNDK_path>uildcmakeandroid.toolchain.cmake" -DCMAKE_MAKE_PROGRAM="<MinGW_path>msys1.0inmake.exe" -DANDROID_TOOLCHAIN=gcc -DANDROID_ABI="armeabi-v7a with NEON" --DCMAKE_BUILD_TYPE="Debug" <source>

这篇关于“C 编译器 [...] 无法编译简单的测试程序"使用 CMake 和 Android NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:“C 编译器 [...] 无法编译简单的测试程序"使用 CMake 和 Android NDK