1. 官方網站:https://www.msys2.org/
2.清華大學鏡像:https://mirror.tuna.tsinghua.edu.cn/help/msys2/
3. 常用操作:https://segmentfault.com/n/1330000004236998
4.msys2包含mingw32和mingw64兩個目錄,pacman安裝的時候查詢的包會出來一堆,要看清楚是mingw32還是mingw64,一不小心就會安裝錯了
一般是用pacman -Sl cmake | grep mingw64這種命令搜索一下
1.cmake
windows下不能像linux下使用命令:
cmake .
這個時候會把項目生成vc的sln文件,實際上pacman安裝的cmake和從cmake官方的工功能是一樣的,默認都是生成vc的sln文件
如果想要linux下生成Makefile文件的功能,執行cmake時要添加下面的選項
cmake -G "MinGW Makefiles" . # 這個有時候有問題 cmake -G "MSYS Makefiles" . # 這個更好一些
2.make
make安裝完之后,文件名是mingw32-make.exe,要手工改成make.exe
3.gdb也需要單獨安裝
pacman -S mingw-w64-x86_64-gdb
4.git bash中使用gcc、make、cmake等命令
mingw64默認是不包含GUN的Toolchain的,msys2的主要作用是提供了pacman工具可以安裝這些Toolchain
我們一般習慣使用git bash,而且他跟文件夾上下文菜單和其他工具的命令行綁定的比較好,所以我更願意在git bash中使用gcc、make、cmake等命令
這個時候PATH中添加C:\msys64\mingw64\bin即可
5.日常開發工具
日常開發調試,要執行cmake、make、./app.exe很煩,可以自己寫一個命令執行這三個命令即可
vs2017和vs2019是支持cmake的,但是我本地環境都報這個錯誤,換成mingw64的ToolChain錯誤是一樣的
1> CMake generation started for configuration: 'x64-Debug'. 1> Command line: "cmd.exe" /c ""C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="D:\git\cv\cmk\cmk04\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "D:\git\cv\cmk\cmk04" 2>&1" 1> Working directory: D:\git\cv\cmk\cmk04\out\build\x64-Debug 1> [CMake] -- The C compiler identification is MSVC 19.25.28612.0 1> [CMake] -- The CXX compiler identification is MSVC 19.25.28612.0 1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe 1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe -- broken 1> [CMake] CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message): 1> [CMake] The C compiler 1> [CMake] 1> [CMake] "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe" 1> [CMake] 1> [CMake] is not able to compile a simple test program. 1> [CMake] 1> [CMake] It fails with the following output: 1> [CMake] 1> [CMake] Change Dir: D:/git/cv/cmk/cmk04/out/build/x64-Debug/CMakeFiles/CMakeTmp 1> [CMake] 1> [CMake] Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_8fabf && [1/2] Building C object CMakeFiles\cmTC_8fabf.dir\testCCompiler.c.obj 1> [CMake] [2/2] Linking C executable cmTC_8fabf.exe 1> [CMake] FAILED: cmTC_8fabf.exe 1> [CMake] cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_8fabf.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\MICROS~3\2019\COMMUN~1\VC\Tools\MSVC\1425~1.286\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_8fabf.dir\testCCompiler.c.obj /out:cmTC_8fabf.exe /implib:cmTC_8fabf.lib /pdb:cmTC_8fabf.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ." 1> [CMake] Active code page: 65001 1> [CMake] The system cannot find the path specified. 1> [CMake] ninja: build stopped: subcommand failed. 1> [CMake] 1> [CMake] 1> [CMake] 1> [CMake] 1> [CMake] 1> [CMake] CMake will not be able to correctly generate this project. 1> [CMake] Call Stack (most recent call first): 1> [CMake] CMakeLists.txt:6 (project) 1> [CMake] -- Configuring incomplete, errors occurred! 1> [CMake] See also "D:/git/cv/cmk/cmk04/out/build/x64-Debug/CMakeFiles/CMakeOutput.log". 1> [CMake] See also "D:/git/cv/cmk/cmk04/out/build/x64-Debug/CMakeFiles/CMakeError.log". 1> [CMake] 1> cmd.exe /c ""C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="D:\git\cv\cmk\cmk04\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "D:\git\cv\cmk\cmk04" 2>&1" returned with exit code: 1