使用 cmake 和 mingw-w64 错误编译测试程序

Posted

技术标签:

【中文标题】使用 cmake 和 mingw-w64 错误编译测试程序【英文标题】:using cmake with mingw-w64 error compiling test program 【发布时间】:2016-04-21 13:57:57 【问题描述】:

我正在尝试使用 mingw-w64 和 cmake 进行简单的编译。但由于某种原因,我不能。它无法验证 gcc 是否可以编译一个奇怪的 C 程序。有任何想法吗?

谢谢

保罗

C:\work\opencv\myown\hello>cmake -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CC_COMPILER=gcc
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-5.3.0-win32-seh-rt_v4-rev0/mingw64/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_8ce25\fast"
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-5.3.0-win32-seh-rt_v4-rev0/mingw64/bin/gcc.exe -- broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "C:/Program
  Files/mingw-w64/x86_64-5.3.0-win32-seh-rt_v4-rev0/mingw64/bin/gcc.exe" is
  not able to compile a simple test program.

  It fails with the following output:

   Change Dir: C:/work/opencv/myown/hello/CMakeFiles/CMakeTmp



  Run Build Command:"nmake" "/NOLOGO" "cmTC_8ce25\fast"



  Generator: execution of make failed.  Make command was: "nmake" "/NOLOGO"
  "cmTC_8ce25\fast"





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:7 (project)


-- Configuring incomplete, errors occurred!
See also "C:/work/opencv/myown/hello/CMakeFiles/CMakeOutput.log".
See also "C:/work/opencv/myown/hello/CMakeFiles/CMakeError.log".

【问题讨论】:

【参考方案1】:

nmake 在您的PATH 中可用吗?

您可以使用 CMAKE_MAKE_PROGRAM 提供另一个 make 命令,例如:

cmake -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CC_COMPILER=gcc -DCMAKE_MAKE_PROGRAM=mingw32-make

【讨论】:

以上是关于使用 cmake 和 mingw-w64 错误编译测试程序的主要内容,如果未能解决你的问题,请参考以下文章

Windows下的 C++ 编译工具(MinGW-w64 + CMake)

ubuntu32bit的系统如何配置mingw-w64的交叉编译toolchain?

cmake mingw-w64:尝试构建时出现奇怪的错误

使用 mingw-w64 编译 mex 的链接器错误

mingw-w64和Linux下的GCC有区别吗

未定义的参考链接 yaml-cpp 程序与 mingw-w64 + cmake