MinGW C编译器“无法编译简单的测试程序” [英] MinGW C compiler "not able to compile a simple test program"
问题描述
我想将MinGW作为C编译器运行。 MinGW已从Chocolatey安装。调用是从gitlab-runner到CMake。失败
I want to run MinGW as a C compiler. MinGW has been installed from Chocolatey. Invocation is from gitlab-runner through CMake. This fails with
$ cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DLIB_MAN=OFF -DCMAKE_INSTALL_PREFIX=C:\opt\x64 -B. ..
-- The C compiler identification is unknown
-- Check for working C compiler: C:/ProgramData/chocolatey/bin/x86_64-w64-mingw32-gcc.exe
-- Check for working C compiler: C:/ProgramData/chocolatey/bin/x86_64-w64-mingw32-gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/ProgramData/chocolatey/bin/x86_64-w64-mingw32-gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/gitlab-runner/builds/zjE1Mkfg/0/mlz/kww/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/ProgramData/chocolatey/bin/mingw32-make.exe cmTC_ffa53/fast && C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/mingw32-make -f CMakeFiles\cmTC_ffa53.dir\build.make CMakeFiles/cmTC_ffa53.dir/build
mingw32-make[1]: Entering directory 'C:/gitlab-runner/builds/zjE1Mkfg/0/mlz/kww/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_ffa53.dir/testCCompiler.c.obj
C:\ProgramData\chocolatey\bin\x86_64-w64-mingw32-gcc.exe -o CMakeFiles\cmTC_ffa53.dir\testCCompiler.c.obj -c C:\gitlab-runner\builds\zjE1Mkfg\0\mlz\kww\build\CMakeFiles\CMakeTmp\testCCompiler.c
mingw32-make[1]: *** [CMakeFiles\cmTC_ffa53.dir\build.make:65: CMakeFiles/cmTC_ffa53.dir/testCCompiler.c.obj] Error 1
mingw32-make[1]: Leaving directory 'C:/gitlab-runner/builds/zjE1Mkfg/0/mlz/kww/build/CMakeFiles/CMakeTmp'
mingw32-make: *** [Makefile:120: cmTC_ffa53/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:6 (project)
-- Configuring incomplete, errors occurred!
See also "C:/gitlab-runner/builds/zjE1Mkfg/0/mlz/kww/build/CMakeFiles/CMakeOutput.log".
See also "C:/gitlab-runner/builds/zjE1Mkfg/0/mlz/kww/build/CMakeFiles/CMakeError.log".
ERROR: Job failed: exit status 1
来自我知道,如果系统上存在 sh.exe
,MinGW肯定会失败。但是, sh.exe
带有几个应用程序,其中包括Git和Visual Studio,我无法删除它们。建议在某处添加 -DCMAKE_SH = CMAKE_SH-NOTFOUND
,但这无效。
From various web sources I understand that MinGW is bound to fail if sh.exe
is present on the system [1]. However, sh.exe
comes with several applications, among them Git and Visual Studio, which I cannot remove. Somewhere it's suggested to add -DCMAKE_SH="CMAKE_SH-NOTFOUND"
, which, however, has no effect.
我从2015年[2]看过一个相关问题,但是涉及到 CLion
。唯一推荐的答案包含几个断开的链接-完全来说,该线程没有帮助。
I've seen a related question from 2015 [2], which however involves CLion
. The only upvoted answer contains several broken links - altogether, that thread isn't helpful.
如何继续?有没有机会解决 sh.exe
问题?
How to proceed? Is there a chance to work around the sh.exe
problem?
网络上的其他建议建议使用 -G MSYS Makefiles
。但是,CMake文档[3]似乎排除了这一点:与Windows命令提示符不兼容。要在Windows命令提示符下进行构建,请使用MinGW Makefiles生成器。
Other advice on the web suggests to use -G "MSYS Makefiles"
. However, the CMake documentation [3] seems to rule this out: "not compatible with a Windows command prompt. To build under a Windows command prompt, use the MinGW Makefiles generator."
[1] https://stackoverflow.com/a/7411982/1017348
[2] CLion:错误:C编译器 C:/MinGW/bin/gcc.exe无法编译简单的测试程序
[3] https://cmake.org/cmake/help/latest/generator/MSYS%20Makefiles.html#generator:MSYS%20Makefiles 每个CMake 3.16.1
[1] https://stackoverflow.com/a/7411982/1017348
[2] CLion: Error:The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test program
[3] https://cmake.org/cmake/help/latest/generator/MSYS%20Makefiles.html#generator:MSYS%20Makefiles per CMake 3.16.1
推荐答案
sh.exe
仅在您运行CMake时出现问题。第一次尝试生成项目时。您可以再次重新运行CMake,CMake将继续进行正常处理以生成项目(在版本 3.16
中进行测试)。我看到一个补丁删除了该支票,应该是将来的CMake版本的一部分。
The sh.exe
is only a problem when you run CMake the first time when trying to generate the project. You can rerun CMake again and CMake will continue with normal processing to generate the project (tested in version 3.16
). I saw a patch that removes this check and should be part of a future release of CMake.
已经提到了 gcc
安装不正确。当有人提到 gcc
失败并显示 Error 1
消息时,情况似乎总是如此。请注意,错误1
不是来自 CMake
。 CMake
只是从运行 mingw32-make
来构建示例项目时收集输出。
It's already mentioned that gcc
is installed incorrectly. That always seems to be the case when anyone mentions that gcc
fails with an Error 1
message. It should be noted that Error 1
is not from CMake
. CMake
is just gathering the output from when it runs mingw32-make
to build the sample project.
输出中的第一条消息-C编译器的标识未知
是一条非常清楚的消息,表明您的编译器无法正常工作。此步骤的所有输出都在CMake在build文件夹中生成的日志和错误文件中。您将能够看到它如何调用编译器,以及带有哪些选项和编译器的输出。
The first message in the output -- The C compiler identification is unknown
is a pretty clear message that your compiler isn't working. All of the output for this step is in the log and error files that CMake generates in the build folder. You'll be able to see how it invoked the compiler and with which options and the output from the compiler.
这篇关于MinGW C编译器“无法编译简单的测试程序”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!