How to invoke cmake from powershell using MinGW generator

后端 未结 1 1062
难免孤独
难免孤独 2021-02-11 03:43

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, ho

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-11 03:57

    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

    0 讨论(0)
提交回复
热议问题