0

I installed MinGW from the official website, and I'm trying to compile a simple cmake project.

I did

cmake -G"MinGw Makefiles" .

and got:

CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "C:/MinGW/bin/gcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/LZ/Desktop/roosek_ocr/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/MinGW/bin/mingw32-make.exe cmTC_3eeac/fast && C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTC_3eeac.dir\build.make CMakeFiles/cmTC_3eeac.dir/build
    mingw32-make.exe[1]: Entering directory 'C:/Users/LZ/Desktop/roosek_ocr/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_3eeac.dir/testCCompiler.c.obj
    C:\MinGW\bin\gcc.exe    -o CMakeFiles\cmTC_3eeac.dir\testCCompiler.c.obj   -c C:\Users\LZ\Desktop\roosek_ocr\CMakeFiles\CMakeTmp\testCCompiler.c
    CMakeFiles\cmTC_3eeac.dir\build.make:81: recipe for target 'CMakeFiles/cmTC_3eeac.dir/testCCompiler.c.obj' failed       mingw32-make.exe[1]: *** [CMakeFiles/cmTC_3eeac.dir/testCCompiler.c.obj] Error 1
    mingw32-make.exe[1]: Leaving directory 'C:/Users/LZ/Desktop/roosek_ocr/CMakeFiles/CMakeTmp'
    Makefile:137: recipe for target 'cmTC_3eeac/fast' failed
    mingw32-make.exe: *** [cmTC_3eeac/fast] Error 2

I found https://stackoverflow.com/a/55941909/6655884 but I looked at my path and I couldn't find sh.exe. Atually I don't know if it's there. How can I check? Typing sh on powershell, it complains that it's not a command or a script or anything.

Other posts talk about MinGw installed through chocolatey, which is not my case.

UPDATE:

Here's the CMakeError.log:

    Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: C:/MinGW/bin/gcc.exe
Build flags:
Id flags: --target=arm-arm-none-eabi;-mcpu=cortex-m3

The output was:
1
gcc.exe: warning: '-mcpu=' is deprecated; use '-mtune=' or '-march=' instead
gcc.exe: error: unrecognized command line option '--target=arm-arm-none-eabi'


Checking whether the C compiler is IAR using "" did not match "IAR .+ Compiler":
gcc.exe: fatal error: no input files
compilation terminated.
Checking whether the C compiler is IAR using "" did not match "IAR .+ Compiler":
gcc.exe: fatal error: no input files
compilation terminated.
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags:

The output was:
1


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags: -c

The output was:
1


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags: --c++

The output was:
1
g++.exe: error: unrecognized command line option '--c++'


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags: --ec++

The output was:
1
g++.exe: error: unrecognized command line option '--ec++'; did you mean '-Weffc++'?


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags: --target=arm-arm-none-eabi;-mcpu=cortex-m3

The output was:
1
g++.exe: warning: '-mcpu=' is deprecated; use '-mtune=' or '-march=' instead
g++.exe: error: unrecognized command line option '--target=arm-arm-none-eabi'


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags:

The output was:
1


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags: -c

The output was:
1


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags: --c++

The output was:
1
g++.exe: error: unrecognized command line option '--c++'


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags: --ec++

The output was:
1
g++.exe: error: unrecognized command line option '--ec++'; did you mean '-Weffc++'?


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags: --target=arm-arm-none-eabi;-mcpu=cortex-m3

The output was:
1
g++.exe: warning: '-mcpu=' is deprecated; use '-mtune=' or '-march=' instead
g++.exe: error: unrecognized command line option '--target=arm-arm-none-eabi'


Checking whether the CXX compiler is IAR using "" did not match "IAR .+ Compiler":
g++.exe: fatal error: no input files
compilation terminated.
Checking whether the CXX compiler is IAR using "" did not match "IAR .+ Compiler":
g++.exe: fatal error: no input files
Determining if the C compiler works failed with the following output:
Run Build Command(s):C:/MinGW/bin/mingw32-make.exe cmTC_3eeac/fast && C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTC_3eeac.dir\build.make CMakeFiles/cmTC_3eeac.dir/build

mingw32-make.exe[1]: Entering directory 'C:/Users/LZ/Desktop/roosek_ocr/CMakeFiles/CMakeTmp'

Building C object CMakeFiles/cmTC_3eeac.dir/testCCompiler.c.obj

C:\MinGW\bin\gcc.exe    -o CMakeFiles\cmTC_3eeac.dir\testCCompiler.c.obj   -c C:\Users\LZ\Desktop\roosek_ocr\CMakeFiles\CMakeTmp\testCCompiler.c

CMakeFiles\cmTC_3eeac.dir\build.make:81: recipe for target 'CMakeFiles/cmTC_3eeac.dir/testCCompiler.c.obj' failed       
mingw32-make.exe[1]: *** [CMakeFiles/cmTC_3eeac.dir/testCCompiler.c.obj] Error 1

mingw32-make.exe: *** [cmTC_3eeac/fast] Error 2
Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • Please look in the `C:/Users/LZ/Desktop/roosek_ocr/CMakeFiles` directory, there should be a log file containing errors. You might get more detailed information from this log file. – Some programmer dude Feb 16 '20 at 07:06
  • "I found https://stackoverflow.com/a/55941909/6655884 but I looked at my path and I couldn't find `sh.exe`. Atually I don't know if it's there." - Just type `sh.exe` in the command line. If it is NOT in the path, then you will got `is not recognized as an internal or external command` error message. In any case, you may start with checking, that your compiler is actually able to compile something. – Tsyvarev Feb 16 '20 at 07:22
  • @Someprogrammerdude I updated the question with the log, please take a look – Guerlando OCs Feb 16 '20 at 16:28
  • It seems that the flags `--target=arm-arm-none-eabi` and `-mcpu=cortex-m3` was passed to the `gcc` program. Why would that be? Are you attempting to cross-compile for ARM systems? What does your `CMakeLists.txt` file look like? What environment variables do you have set in PowerShell? – Some programmer dude Feb 16 '20 at 19:37
  • @Someprogrammerdude I did not pass anything reated to arm. Please take a look at my CMakeLists file: https://stackoverflow.com/questions/60250900/qt-and-cmake-on-windows-lnk2019-unresolved-external-symbol-errors and I have not added any power shell variables. – Guerlando OCs Feb 16 '20 at 20:35

1 Answers1

0

I've run into this issue as well and am still looking for a solution. The only way I've been able to get around this issue is to add the CMAKE_CXX_COMPILER_WORKS=1 flag.

paperplate
  • 17
  • 4