问题
I'm trying to compile Google Test with Mingw-w64 in a Windows 10 machine but I always get the error:
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!
This is is what I'm doing:
- Open a Windows CMD terminal and change folder t where I downloaded google test
- Add CMake, make and g++ to the path
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%
- Run CMake with
cmake CMakeLists.txt -G "MinGW Makefiles"
These are the versions of the tools:
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 version 3.15.3
- g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
Make comes from the MSYS package from Mingw-64w. I cloned Google Test from here
Any help is much appreciated!
EDIT 1
None of the solutions in CMake/MinGW unknown compilers, gcc.exe broken work.
EDIT 2
I also tried using environment variables to tell CMake which tools to use.
- Added the tools' folders to the 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%
- Calling CMake with
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"
I get this error:
-- 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".
As g++ and gcc are in the PATH, I also tried to call CMake like so:
cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DCMAKE_MAKE_PROGRAM="mingw32-make.exe" CMakeLists.txt -G "MinGW Makefiles"
Which yields the same error as the previous try:
-- 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".
However, I CAN call g++
:
C:\git\tdd\googletest>g++
g++: fatal error: no input files
compilation terminated.
Thanks again!
回答1:
Your original problems stem from the choice of using make.exe for MSYS2 together with the MinGW-w64 compiler, which is not supported by that version of make.exe. The correct program to use with MinGW-w64 is mingw32-make.exe, which is part of the MinGW-w64 distribution. I am not fully able to follow your later edits, but for instance this works perfectly well in 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
Here, I used:
- CMake 3.15.2,
- MinGW-w64 8.1.0 (x86_64-8.1.0-posix-seh-rt_v6-rev0),
- and current git revision of Google Test.
回答2:
OK, I managed to compile it using CMDER's Bash console. Assuming you have Mingw-w64 installed at C:\mingw-w64\
(no spaces in the path), these steps will get you a working Google test library under Mingw-w64
- Set the PATH to:
PATH=/c/Program\ Files/CMake/bin:/c/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin:$PATH
- Invoke CMake with
cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_MAKE_PROGRAM=mingw32-make.exe CMakeLists.txt -G 'MSYS Makefiles'
- Build with
mingw32-make.exe -j8
I'm gonna go on a limb here and say this probably should work with the Git Bash shell. I still don't have a solution for building it with the regular Windows CMD terminal.
来源:https://stackoverflow.com/questions/58758585/compiling-google-test-with-mingw-w64