# Cmake Mingw makefile in windows

**URL:** https://discourse.cmake.org/t/cmake-mingw-makefile-in-windows/6908
**Category:** Usage
**Tags:** os:windows, comp:msvc, gen:makefiles
**Created:** [November 19, 2022, 10:55am UTC](https://discourse.cmake.org/t/cmake-mingw-makefile-in-windows/6908 "2022-11-19T10:55:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Gaurav\_Tiwari](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gaurav_tiwari/32/2932_2.png) [@Gaurav\_Tiwari](https://discourse.cmake.org/u/Gaurav_Tiwari)
#### Post date: [November 19, 2022, 10:55am UTC](https://discourse.cmake.org/t/cmake-mingw-makefile-in-windows/6908/1 "2022-11-19T10:55:56Z")

</div>

I am trying to create a build of MinGW Makefiles using cmake but I get the following error when I execute the command `cmake -G "MinGW Makefiles" ..\source\` I have added mingw bin and cmake to my path. I get the following error on running the cmake -G commmand. I am trying to create a build of MinGW Makefiles using cmake but I get the following error when I execute the command `cmake -G "MinGW Makefiles" ..\source\` I am trying to avoid adding the compiler to be used in the cmakelist.txt file as I saw that it is a bad practice. I searched and found alternative approaches using -D flag and saving the preferred settings in cache but I am curious to know why this one works in the tutorial but not on my system… I get the following error on running the cmake -G commmand

```nohighlight
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: C:/Users/gaura.YASH/OneDrive/Desktop/new_code/cmake_1st_proj/C-Make/1st project/build/CMakeFiles/CMakeScratch/TryCompile-mhmynt

Run Build Command(s):C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_29120/fast && C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTC_29120.dir\build.make CMakeFiles/cmTC_29120.dir/build
mingw32-make.exe[1]: Entering directory 'C:/Users/gaura.YASH/OneDrive/Desktop/new_code/cmake_1st_proj/C-Make/1st project/build/CMakeFiles/CMakeScratch/TryCompile-mhmynt'
Building CXX object CMakeFiles/cmTC_29120.dir/testCXXCompiler.cxx.obj
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_29120.dir\testCXXCompiler.cxx.obj.d --working-dir="C:\Users\gaura.YASH\OneDrive\Desktop\new_code\cmake_1st_proj\C-Make\1st project\build\CMakeFiles\CMakeScratch\TryCompile-mhmynt" --filter-prefix="Note: including file: " -- C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\cl.exe /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\cmTC_29120.dir\testCXXCompiler.cxx.obj /FdCMakeFiles\cmTC_29120.dir/ /FS -c "C:\Users\gaura.YASH\OneDrive\Desktop\new_code\cmake_1st_proj\C-Make\1st project\build\CMakeFiles\CMakeScratch\TryCompile-mhmynt\testCXXCompiler.cxx"
testCXXCompiler.cxx
Linking CXX executable cmTC_29120.exe
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\cmTC_29120.dir\link.txt --verbose=1
"C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_29120.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_29120.dir\objects1 /out:cmTC_29120.exe /implib:cmTC_29120.lib /pdb:"C:\Users\gaura.YASH\OneDrive\Desktop\new_code\cmake_1st_proj\C-Make\1st project\build\CMakeFiles\CMakeScratch\TryCompile-mhmynt\cmTC_29120.pdb" /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib
RC Pass 1: command "rc /fo CMakeFiles\cmTC_29120.dir/manifest.res CMakeFiles\cmTC_29120.dir/manifest.rc" failed (exit code 0) with the following output:
The system cannot find the file specifiedCMakeFiles\cmTC_29120.dir\build.make:99: recipe for target 'cmTC_29120.exe' failed
mingw32-make.exe[1]: *** [cmTC_29120.exe] Error -1
mingw32-make.exe[1]: Leaving directory 'C:/Users/gaura.YASH/OneDrive/Desktop/new_code/cmake_1st_proj/C-Make/1st project/build/CMakeFiles/CMakeScratch/TryCompile-mhmynt'
Makefile:126: recipe for target 'cmTC_29120/fast' failed
mingw32-make.exe: *** [cmTC_29120/fast] Error 2

CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred! See also "C:/Users/gaura.YASH/OneDrive/Desktop/new_code/cmake_1st_proj/C-Make/1st project/build/CMakeFiles/CMakeOutput.log". See also "C:/Users/gaura.YASH/OneDrive/Desktop/new_code/cmake_1st_proj/C-Make/1st project/build/CMakeFiles/CMakeError.log". PS C:\Users\gaura.YASH\OneDrive\Desktop\new_code\cmake_1st_proj\C-Make\1st project\build>

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 19, 2022, 11:07pm UTC](https://discourse.cmake.org/t/cmake-mingw-makefile-in-windows/6908/2 "2022-11-19T23:07:52Z")

</div>

It looks like it is picking up a VS toolchain. Are you in a Visual Studio Developer command prompt? You should be in a MinGW prompt instead. Also note that a MinGW CMake build is required to build with MinGW; the stock Windows release targets the native platform.

---

<div class="post-metadata">

### Author: ![waydan](https://discourse.cmake.org/user_avatar/discourse.cmake.org/waydan/32/4083_2.png) [@waydan](https://discourse.cmake.org/u/waydan)
#### Post date: [January 4, 2024, 8:47pm UTC](https://discourse.cmake.org/t/cmake-mingw-makefile-in-windows/6908/3 "2024-01-04T20:47:59Z")

</div>

I’m running into this issue too. CMake is detecting my installation of MSVC 2017 and then produces the same error seen by Tiwari. FWI: I’m building on Windows and opening my shell in VS Code. Do I need a different installation of CMake? I only see one installer for Windows x64. I’d really like to run my configuration step with just `cmake -S . -B build -G "MinGW Makefiles"`.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [January 5, 2024, 4:08pm UTC](https://discourse.cmake.org/t/cmake-mingw-makefile-in-windows/6908/4 "2024-01-05T16:08:47Z")

</div>

I use MinGW regularly, even in msvc environment but I force the compiler on cmake command line, it may be the way to go (otherwise it actually seems that some autodetection kicks in).  
  
Hope it helps

---

<div class="post-metadata">

### Author: ![waydan](https://discourse.cmake.org/user_avatar/discourse.cmake.org/waydan/32/4083_2.png) [@waydan](https://discourse.cmake.org/u/waydan)
#### Post date: [January 5, 2024, 4:22pm UTC](https://discourse.cmake.org/t/cmake-mingw-makefile-in-windows/6908/5 "2024-01-05T16:22:58Z")

</div>

Thanks, that does help. I added `-DCMAKE_C_COMPILER=gcc` and it fixed the computer detection.
