用Mingw-w64编译Google测试

问题描述 投票:1回答:2

我正在尝试在Windows 10计算机中使用Mingw-w64编译Google Test,但我总是收到错误消息:

C:\git\tdd\googletest>cmake CMakeLists.txt -G "MinGW Makefiles"
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

这就是我在做什么:

  1. 打开Windows CMD终端并更改我下载Google测试的文件夹t
  2. 将CMake,make和g ++添加到路径set PATH="C:\Program Files\CMake\bin";"C:\msys\bin";"C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin";%PATH%
  3. 使用cmake CMakeLists.txt -G "MinGW Makefiles"运行CMake

这些是工具的版本:

GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i686-pc-msys
  • cmake版本3.15.3
  • g ++(i686-posix-dwarf-rev0,由MinGW-W64项目构建)8.1.0

[来自MSYS package from Mingw-64w。我从here

克隆了Google测试

非常感谢您的帮助!

编辑1

CMake/MinGW unknown compilers, gcc.exe broken中的所有解决方案均不起作用。

编辑2

我还尝试使用环境变量来告诉CMake使用哪些工具。

  1. 将工具的文件夹添加到PATH:

set PATH="C:\Program Files\CMake\bin";"C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin";%PATH%

  1. 通过调用CMake

cmake -DCMAKE_C_COMPILER="C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++" -DCMAKE_MAKE_PROGRAM="C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/mingw32-make.exe" CMakeLists.txt -G "MinGW Makefiles"

我收到此错误:

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:10 (project):
  The CMAKE_C_COMPILER:

    C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:10 (project):
  The CMAKE_CXX_COMPILER:

    C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "C:/git/tdd/googletest/CMakeFiles/CMakeOutput.log".
See also "C:/git/tdd/googletest/CMakeFiles/CMakeError.log".

由于g ++和gcc在PATH中,所以我也试图像这样调用CMake:

cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DCMAKE_MAKE_PROGRAM="mingw32-make.exe" CMakeLists.txt -G "MinGW Makefiles"

与上一次尝试产生相同的错误:

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:10 (project):
  The CMAKE_C_COMPILER:

    gcc

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:10 (project):
  The CMAKE_CXX_COMPILER:

    g++

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "C:/git/tdd/googletest/CMakeFiles/CMakeOutput.log".
See also "C:/git/tdd/googletest/CMakeFiles/CMakeError.log".

但是,我CAN呼叫g++

C:\git\tdd\googletest>g++
g++: fatal error: no input files
compilation terminated.

再次感谢!

c++ cmake googletest mingw-w64
2个回答
0
投票

[确定,我设法使用CMDER的Bash控制台对其进行了编译。假设您在C:\mingw-w64\上安装了Mingw-w64(路径中没有空格),这些步骤将使您在Mingw-w64下获得可以使用的Google测试库

  1. 将路径设置为:

PATH=/c/Program\ Files/CMake/bin:/c/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin:$PATH

  1. 使用调用CMake

cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_MAKE_PROGRAM=mingw32-make.exe CMakeLists.txt -G 'MSYS Makefiles'

  1. 构建方式

mingw32-make.exe -j8

我将在这里弯腰,说这可能应该与Git Bash外壳一起使用。我仍然没有使用常规Windows CMD终端构建它的解决方案。


0
投票

您的原始问题源于对MSYS2使用make.exe的选择与MinGW-w64编译器一起使用,该版本的make.exe不支持该编译器。与MinGW-w64一起使用的正确程序是mingw32-make.exe,它是MinGW-w64发行版的一部分。我不能完全按照您以后的编辑进行操作,但是例如,在[[cmd.exe:

中,此方法就可以很好地工作set "PATH=C:\Program Files\CMake\bin;%PATH%" set "PATH=C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;%PATH%" cmake ^ -G "MinGW Makefiles" ^ -D CMAKE_C_COMPILER=gcc.exe ^ -D CMAKE_CXX_COMPILER=g++.exe ^ -D CMAKE_MAKE_PROGRAM=mingw32-make.exe ^ . mingw32-make.exe
[我在这里使用:

© www.soinside.com 2019 - 2024. All rights reserved.