3

I'm trying an hello world test to make cmake under Windows, using MinGW as compiler. This answer suggests to run cmake with the -G flag as following:

 cmake -G "MinGW Makefiles" .

However, if I do this, I get a message saying that that is not a known generator. Indeed, running cmake --help, under the Generators section it lists the following generators:

enter image description here

and as you can see, "MinGW Makefiles" is not listed.

If this is relevant, I have MinGW installed and working on my system in the usual folder C:\MinGW. I also have MinGW-w64 installed through WinBuilds and MSYS2, again in the default installation folders. I'm using cmake version 3.5.2, installed through MSYS2.

Why is "MinGW Makefiles" not listed among the generators?

Community
  • 1
  • 1
glS
  • 1,209
  • 6
  • 18
  • 45

1 Answers1

6

Only the Windows version of CMake does know the MinGW Makefiles and MSYS Makefiles generators.

If you have downloaded the MinGW/MSYS CMake version try using the Unix Makefiles generator or don't use the -G option (to auto-detect your compiler toolchain).

If you still get errors, please see the references below.

References

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149
  • thanks, that makes sense. The reason I tried to use that flag is that I otherwise get another error, as cmake does not recognise the C compiler, which is the mingw64 gcc compiler obtained through MSYS2, that I specified in the `CMakeLists.txt` file. Can I use the `cmake` obtained from their official website to build the makefiles, even though I want to use the other tools provided by MSYS2? – glS Jun 27 '16 at 18:43
  • @glS Did you also install CMake via `pacman` as in the first reference I have provided? And yes, I've only downloaded and installed the [official Windows CMake version](https://cmake.org/download/), call `cmake` from MSYS and haven't encountered any problems so far. For a basic sanity check of your CMake/MinGW/MSYS installtion see [here](http://stackoverflow.com/questions/32801638). And I admit I don't understand your comment about specifying your GCC compiler in your `CMakeLists.txt` file. Sound like something you shouldn't do. Can you please add that script part to your question also? – Florian Jun 27 '16 at 18:50
  • yes I installed it via the `pacman` provided by the MSYS shell. I installed the official Windows version of `cmake` and it now does work in the simplest example with VS that you provide in the point 1 of your [linked answer](http://stackoverflow.com/a/32830625/4063051). This is definetely a step forward, I will now try and make it use the mingw installed through MSYS. Thanks again! – glS Jun 27 '16 at 18:56
  • 1
    sorry to bother you again. In case you incurred in the same problem: is there a workaround to avoid the problem of having `sh.exe` in the PATH and using "MinGW Makefiles" as generator? Because I have an `sh.exe` in the PATH given by a git distribution and I kind of wanted to stay there, if possible. Did you know any easy solution to this? – glS Jun 27 '16 at 19:24
  • @glS Did you run the MSYS post-install step as described [here](https://sourceforge.net/p/mingw-w64/wiki2/MSYS/)? This sets the paths to MinGW and then CMake can detect the right compilers (no need to list them in your `CMakeLists.txt`). The error message you get is: "sh.exe was found in your PATH, here: ... For MinGW make to work correctly sh.exe must NOT be in your path. ... If you want to use a UNIX shell, then use MSYS Makefiles."? So to not have conflicts with another GNU toolchain (not so much with another `sh.exe`), use "MSYS Makefiles" (that's what I do). – Florian Jun 28 '16 at 10:42
  • sorry, I meant to say that I'm using MSYS2. The instructions there seem to be about the previous version of MSYS, am I right? The reason I was trying to use MinGW makefiles is that on the [MSYS CMake doc page](https://cmake.org/cmake/help/v3.1/generator/MSYS%20Makefiles.html) it says that *They are not compatible with a Windows command prompt*, which I interpreted as meaning that I would have had troubles working with powershell, which is what I usually do. Or does that mean something else, and I can work safely with MSYS and PS? – glS Jun 28 '16 at 10:52