c++ - 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
解决方案
默认情况下,Gradle 会尝试查找与您的系统架构相匹配的工具链 ( x86_64
),但您只有 32 位 MinGW
一种解决方法是在 Gradle 脚本中显式配置 32 位目标:
application {
targetMachines = [ machines.windows.x86 ]
}
推荐阅读
- web-services - 网站如何检测本地网络上的设备
- reactjs - Reactjs:我可以使用状态安全地访问兄弟组件吗?
- swift - 条件一致性:不支持使用“T”作为符合“T”的具体类型
- java - 当我搜索值时如何防止表中的重复
- laravel - 在 Laravel 中限制哈希的长度
- javascript - 在 React 组件中渲染脚本标签
- mysql - 无法连接到 Windows 机器上 Docker 上托管的 Mysql
- node.js - 无法读取未定义的属性“错误”。有什么问题?
- python - 使用嵌套列表将 comp 变量作为范围参数列出?
- c# - z轴旋转调试不为0,在inspector中为0