MinGw can't compile test file from cmake

独自空忆成欢 提交于 2020-03-05 01:36:56

问题


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

来源:https://stackoverflow.com/questions/60246132/mingw-cant-compile-test-file-from-cmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!