首页 > 解决方案 > Gradle Cpp-Application 未在 Windows 中检测到 gcc

问题描述

我开始更多地进入 c++ 并且我已经开始学习 gradle 以用作它的构建。我正在使用 gradle 的 cpp-application 插件来编译代码。但是,当我尝试构建它时,gradlew 告诉我它无法检测到 gcc,这是我唯一安装的编译器。

我大部分时间都遵循了 gradle 网站上的指南(https://guides.gradle.org/building-cpp-executables/)。到目前为止,这就是我想出大部分代码的地方。

我在我的路径中正确安装了来自 ming-w32 的 gcc(我可以从命令提示符和 make 运行它而没有任何问题)

我还使用了 gradle 5.2.1 制作的 gradlew install

在大多数情况下,我使用 gradle 指南中的确切设置。

apply plugin : 'cpp-application' 

application {
    baseName = "test" 
}

^ /$Project/build.gradle

这是我运行时的命令行输出gradlew assemble

* What went wrong:
Execution failed for task ':compileDebugCpp'.
> No tool chain is available to build C++ for host operating system 'Windows 10' architecture 'x86-64':
    - Tool chain 'visualCpp' (Visual Studio):
        - Could not locate a Visual Studio installation, using the command line tool, Windows registry or system path.
    - Tool chain 'gcc' (GNU GCC):
        - Could not determine GCC metadata: failed to execute gcc.exe -m64 -dM -E -v -.
    - Tool chain 'clang' (Clang):
        - Could not find C++ compiler 'clang++' in system path.

当我运行他们说无法在同一命令提示符下执行的命令时(gcc.exe -m64 -dM -E -v -.

我确实从 gcc 得到输出,没有任何我可以看到的错误

如果你对它的输出感到好奇,你可以在这里找到

我希望问题不在于我的 cpp 代码,因为它无法识别编译器,但它相当短,所以我也可以。

#include <iostream>  

int main(int argc, char** argv) {
  std::cout << "Hello World!!" << std::endl;
  return 0;
}

^ /$Project/src/main/cpp/main.cpp

标签: c++windowsgradlegcc

解决方案


默认情况下,Gradle 会尝试查找与您的系统架构相匹配的工具链 ( x86_64),但您只有 32 位 MinGW

一种解决方法是在 Gradle 脚本中显式配置 32 位目标:

application {
  targetMachines = [ machines.windows.x86 ]
}

推荐阅读