gcc - CLion:错误:C 编译器 "C:/MinGW/bin/gcc.exe"无法编译简单的测试程序

标签 gcc cmake mingw clion

我正在尝试使用 MinGW 在 Windows 7 上运行 CLion,但由于某种原因 CMake 无法编译简单的测试程序,但是当我创建一个简单的 hello world 文件时,当我直接调用编译器而不是 CMake 时,它​​编译得很好.

我已经尝试了 MinGW 的多个版本,但它对错误没有影响。我什至卸载了我的 AV,看看这是否是问题所在,但再次没有任何改变。

我的路径中有 MinGW,还有 CMake。起初我以为这可能是 TEMP 文件夹权限的问题,但它们看起来都很好。我也是管理员帐户。

这是我在 CLion 中遇到的错误:

Error:The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/Jim/.clion10/system/cmake/generated/4cb6a70c/4cb6a70c/__default__/CMakeFiles/CMakeTmp
Run Build Command:"C:/MinGW/bin/mingw32-make.exe" "cmTryCompileExec141319549/fast"
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTryCompileExec141319549.dir\build.make CMakeFiles/cmTryCompileExec141319549.dir/build
mingw32-make.exe[1]: Entering directory 'C:/Users/Jim/.clion10/system/cmake/generated/4cb6a70c/4cb6a70c/__default__/CMakeFiles/CMakeTmp'
"C:\Program Files (x86)\JetBrains\CLion 1.0\bin\cmake\bin\cmake.exe" -E cmake_progress_report C:\Users\Jim\.clion10\system\cmake\generated\4cb6a70c\4cb6a70c\__default__\CMakeFiles\CMakeTmp\CMakeFiles 1
CMakeFiles\cmTryCompileExec141319549.dir\build.make:56: recipe for target 'CMakeFiles/cmTryCompileExec141319549.dir/testCCompiler.c.obj' failed
process_begin: CreateProcess(C:\Users\Jim\AppData\Local\Temp\make68804-1.bat, C:\Users\Jim\AppData\Local\Temp\make68804-1.bat, ...) failed.
make (e=2): Het systeem kan het opgegeven bestand niet vinden.
mingw32-make.exe[1]: *** [CMakeFiles/cmTryCompileExec141319549.dir/testCCompiler.c.obj] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/Users/Jim/.clion10/system/cmake/generated/4cb6a70c/4cb6a70c/__default__/CMakeFiles/CMakeTmp'
Makefile:117: recipe for target 'cmTryCompileExec141319549/fast' failed
mingw32-make.exe: *** [cmTryCompileExec141319549/fast] Error 2
CMake will not be able to correctly generate this project.

这是我尝试从 CMD 使用 CMake 时遇到的错误:enter image description here

最佳答案

通过一个虚拟的 cmake 项目(一个 CMakeLists.txt,仅包含 cmake_minimum_required(VERSION 2.8)add_executable(helloWorld <your hello world program>) 。),我们已经确定编译器和 CLion 不是问题,所以这可能与 make 有关。 Here是日志。

我的猜测是你的路径中有msys。如果sh.exe在你的路径中,它是 known to cause problems .

作为安全的替代方案,您可以决定使用 ninja作为 make 的替代方案( cmake supports it experimentally ,但实际上它支持得很好)。 Here您可以找到预构建的软件包(事实上,它只是您必须放入路径中的一个可执行文件)。

CLion 中的 Ninja 集成 should work just fine .

关于gcc - CLion:错误:C 编译器 "C:/MinGW/bin/gcc.exe"无法编译简单的测试程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29883383/

相关文章:

c - 为什么使用 -O(1/2/3) 选项进行优化会干扰 scanf()?

c++ - 除了更改环境变量 "PATH"之外,您还需要做什么才能让 Eclipse 识别 MinGW ?

c++ - constructor is private error using singleton c++ 和在此上下文错误

ffmpeg - 为 Windows 64 位应用程序构建静态 FFmpeg 库

c - C中的非无意义优化

c++ - 将 g++ 4.8 链接到 libstdc++

c++ - C++如何使用CMakeList.txt链接mongoc和mongocxx静态库

c++ - 使用MinGW播放声音

c++ - 有人可以解释为什么我的 cmake 文件无法构建我的 cpp 文件吗?

c++ - 在 Boost.Test 和现代 CMake 中使用多个测试文件