MinGw 无法从 cmake 编译测试文件 [英] MinGw can't compile test file from cmake

查看:54
本文介绍了MinGw 无法从 cmake 编译测试文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从官网安装了MinGW,我正在尝试编译一个简单的cmake项目.

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

我做到了

cmake -G"MinGw Makefiles" .

并得到:

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

我找到了 https://stackoverflow.com/a/55941909/6655884 但我查看了我的路径找不到 sh.exe.实际上我不知道它是否在那里.我该如何检查?在 powershell 上键入 sh,它抱怨它不是命令或脚本或任何东西.

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.

其他帖子讨论了通过 Chocolatey 安装的 MinGw,这不是我的情况.

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

更新:

这是 CMakeError.log:

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

推荐答案

我也遇到了这个问题,仍在寻找解决方案.我能够解决这个问题的唯一方法是添加 CMAKE_CXX_COMPILER_WORKS=1 标志.

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.

这篇关于MinGw 无法从 cmake 编译测试文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆