title: MinGW C compiler "not able to compile a simple test program"
body: <p>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</p>
  
  <pre><code>$ 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 &amp;&amp; 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
  </code></pre>
  
  <p>From various web sources I understand that MinGW is bound to fail if <code>sh.exe</code> is present on the system [1]. However, <code>sh.exe</code> comes with several applications, among them Git and Visual Studio, which I cannot remove. Somewhere it's suggested to add <code>-DCMAKE_SH="CMAKE_SH-NOTFOUND"</code>, which, however, has no effect.</p>
  
  <p>I've seen a related question from 2015 [2], which however involves <code>CLion</code>. The only upvoted answer contains several broken links - altogether, that thread isn't helpful.</p>
  
  <p>How to proceed? Is there a chance to work around the <code>sh.exe</code> problem?</p>
  
  <p>Other advice on the web suggests to use <code>-G "MSYS Makefiles"</code>. 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."</p>
  
  <p>[1] <a href="https://stackoverflow.com/a/7411982/1017348">https://stackoverflow.com/a/7411982/1017348</a><br>
  [2] <a href="https://stackoverflow.com/questions/29883383">CLion: Error:The C compiler &quot;C:/MinGW/bin/gcc.exe&quot; is not able to compile a simple test program</a><br>
  [3] <a href="https://cmake.org/cmake/help/latest/generator/MSYS%20Makefiles.html#generator:MSYS%20Makefiles" rel="nofollow noreferrer">https://cmake.org/cmake/help/latest/generator/MSYS%20Makefiles.html#generator:MSYS%20Makefiles</a> per CMake 3.16.1</p>