# cmake + mingw32: invalid option '-?'

**URL:** https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344
**Category:** Code
**Tags:** os:windows, comp:mingw
**Created:** [March 31, 2022, 9:31am UTC](https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344 "2022-03-31T09:31:41Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![hydroconstructor](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hydroconstructor/32/2315_2.png) [@hydroconstructor](https://discourse.cmake.org/u/hydroconstructor)
#### Post date: [March 31, 2022, 9:31am UTC](https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344/1 "2022-03-31T09:31:41Z")

</div>

Can’t compile anything by cmake, including Step 1 tutorial example. There is my CMakeLists.txt:

```auto
cmake_minimum_required(VERSION 3.10)

set( CMAKE_CXX_COMPILER "c:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe" )
set( CMAKE_C_COMPILER "c:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/gcc.exe" )
set( CMAKE_MAKE_PROGRAM "c:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" )

# set the project name
project(Tutorial)

# add the executable
add_executable(Tutorial tutorial.cxx)

```

cmake returns error:

```auto
CMake Error at CMakeLists.txt:8 (project):
  Running

   'c:/PROGRA~1/MINGW-~1/X86_64~1.0-W/mingw64/bin/mingw32-make.exe' '-?'

  failed with:

   c:/PROGRA~1/MINGW-~1/X86_64~1.0-W/mingw64/bin/mingw32-make.exe: invalid option -- ?

  Usage: mingw32-make.exe [options] [target] ...

  Options:

    -b, -m Ignored for compatibility.
    -B, --always-make Unconditionally make all targets.
(long list of all mingw32-make options )

```

Why cmake run mingw32-make.exe with option ‘-?’ ? Tried to find answer via Internet, but found nothing ☹

---

<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: [March 31, 2022, 2:06pm UTC](https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344/2 "2022-03-31T14:06:14Z")

</div>

What is the CMake command line you’re using? I would guess that you’re probably using a Windows CMake build which is trying to use MSBuild internally. Rather than setting the compilers in the CMake source directly, it is recommended that you instead just run CMake from a MinGW environment and let it discover things on its own.

---

<div class="post-metadata">

### Author: ![hydroconstructor](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hydroconstructor/32/2315_2.png) [@hydroconstructor](https://discourse.cmake.org/u/hydroconstructor)
#### Post date: [March 31, 2022, 2:19pm UTC](https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344/3 "2022-03-31T14:19:06Z")

</div>

Yes, I use a Windows CMake. Run it by the simplest command:

```auto
cmake .

```

Current directory is source files directory, of course.  
How can I use CMake from a MinGW environment? I do not use graphic interfaces, just command line tools. Should I run something from mingw bin directory to do it?  
By the way, I think there must be a way to explicitly point to CMake which build tool to use.

---

<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: [March 31, 2022, 2:24pm UTC](https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344/4 "2022-03-31T14:24:56Z")

</div>

That will probably use a Visual Studio generator. Trying to get that to use MinGW is certainly doomed to failure. Your MinGW source should have a package manager to be able to get its `cmake` (`pacman`?).

---

<div class="post-metadata">

### Author: ![hydroconstructor](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hydroconstructor/32/2315_2.png) [@hydroconstructor](https://discourse.cmake.org/u/hydroconstructor)
#### Post date: [March 31, 2022, 2:28pm UTC](https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344/5 "2022-03-31T14:28:57Z")

</div>

So, this line of my CMakeLists.txt

```auto
set( CMAKE_MAKE_PROGRAM "c:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" )

```

is completely useless? And CMake tries to use Visual Studio nmake instead of it?

---

<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: [March 31, 2022, 2:32pm UTC](https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344/6 "2022-03-31T14:32:02Z")

</div>

No? Without a `-G`, Windows CMake defaults to Visual Studio for its builds. Neither NMake nor MinGW make is going to work under such expectations.

---

<div class="post-metadata">

### Author: ![hydroconstructor](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hydroconstructor/32/2315_2.png) [@hydroconstructor](https://discourse.cmake.org/u/hydroconstructor)
#### Post date: [March 31, 2022, 2:35pm UTC](https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344/7 "2022-03-31T14:35:32Z")

</div>

So I should run CMake in such way:

```auto
cmake -G "MinGW Makefiles" .

```

?

Is there any way to point this in CMakeLists.txt? Or only in command line?

---

<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: [March 31, 2022, 2:37pm UTC](https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344/8 "2022-03-31T14:37:00Z")

</div>

The CMake code cannot affect the generator; it must be set on the command line (or through the `CMAKE_GENERATOR` environment variable).

---

<div class="post-metadata">

### Author: ![hydroconstructor](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hydroconstructor/32/2315_2.png) [@hydroconstructor](https://discourse.cmake.org/u/hydroconstructor)
#### Post date: [March 31, 2022, 2:39pm UTC](https://discourse.cmake.org/t/cmake-mingw32-invalid-option/5344/9 "2022-03-31T14:39:41Z")

</div>

Thank you for an explanation
