如何使用MinGW生成器从powershell调用cmake

时间:2015-03-20 10:37:12

标签: c++ powershell cmake

我正在尝试从powershell调用cmake,以便我可以使用MinGW编译器构建项目。它适用于Visual Studio生成器,它也可以在我使用cmake-gui时工作,但是从powershell我得到了这个错误:

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

某种类型的开关会使cmake对错误更加冗长会很好,当我使用gui运行cmake时我得到了这个输出:

-- 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 个答案:

答案 0 :(得分:1)

我已经测试了您的powershell cmake电话,如果我 在我的PATH环境变量中有MinGw,则可以重现该问题:

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.

实际上我有一些错误弹出窗口cc1plus.exe has stopped working。此文件与MinGW\bin路径中的DLL有一些依赖关系(在我的安装中,例如libgmp-10.dlllibmpc-3.dlllibmpfr-4.dll)。我已经使用Microsoft的Dependency Walker来分析问题。

但是我使用/安装Dr. Mingw检查未处理的MinGW异常也有非常好的结果。

<强>结论

我非常确定从您的powershell直接调用C:\Qt\Tools\mingw491_32\bin\g++.exe会失败。因此,您示例中最可能的原因是PATH环境变量中缺少MinGW搜索路径:

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

使用额外的搜索路径,它在我的环境中工作。

<强>参考