问题
I am trying to invoke cmake from powershell so that I can build project with MinGW compiler. It works fine for Visual Studio generator, and it also work when I use cmake-gui, however from powershell I get this error:
cmake ..\..\huggle -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=C:\Qt\Tools\mingw491_32\bin\mingw32-make.exe
-- The C compiler identification is unknown
-- Check for working C compiler: C:/Qt/Tools/mingw491_32/bin/gcc.exe
-- Check for working C compiler: C:/Qt/Tools/mingw491_32/bin/gcc.exe -- broken
cmake : CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/CMakeTestCCompiler.cmake:61 (message):
At line:1 char:1
+ cmake ..\..\huggle -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=C:\Qt\Tools\mingw49 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CMake Error at ...e:61 (message)::String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Some kind of switch that would make cmake be more verbose about the error would be nice, when I run cmake using gui I get this output:
-- The C compiler identification is GNU 4.9.1
-- The CXX compiler identification is GNU 4.9.1
-- Check for working C compiler: C:/Qt/Tools/mingw491_32/bin/gcc.exe
-- Check for working C compiler: C:/Qt/Tools/mingw491_32/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw491_32/bin/g++.exe
-- Check for working CXX compiler: C:/Qt/Tools/mingw491_32/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonLibs: C:/Python34/libs/libpython34.a (found version "3.4.1")
-- Configuring done
-- Generating done
回答1:
I've tested your powershell cmake
call and could reproduce the problem if I don't have MinGw in my PATH
environment variable:
PS> cmake .. -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=C:\MinGW\bin\mingw32-make.exe
-- The CXX compiler identification is unknown
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.3/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler "C:/MinGW/bin/g++.exe" is not able to compile a simple
test program.
Actually I got some error popups saying cc1plus.exe has stopped working
. This file has some dependencies to DLLs in the MinGW\bin
path (in my installation e.g. libgmp-10.dll
, libmpc-3.dll
or libmpfr-4.dll
). I've used Microsoft's Dependency Walker to analyze the the problem.
But I have also had very good results checking for unhandled MinGW exceptions using/installing Dr. Mingw.
Conclusion
I'm pretty sure that a direct call to C:\Qt\Tools\mingw491_32\bin\g++.exe
from your powershell will fail. So the most likely reason in your example is a missing MinGW search path in your PATH
environment variable:
PS> $env:Path += ";C:\Qt\Tools\mingw491_32\bin"
PS> cmake ..\..\huggle -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=C:\Qt\Tools\mingw491_32\bin\mingw32-make.exe
With the additonal search path it was working in my environment.
References
- Setting Windows PowerShell path variable
来源:https://stackoverflow.com/questions/29164545/how-to-invoke-cmake-from-powershell-using-mingw-generator