1 安装vscode和c++扩展
2 安装MSYS2
2.1 安装mingw工具链(内含g++等工具)
在MSYS2 MSYS
窗口运行
bash
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
2.2 添加环境变量
- 在开始菜单搜索
编辑系统环境变量
- 编辑
Path
,将msys64\ucrt64\bin
的绝对路径添加进去
2.3 验证安装
Win+R
并输入cmd
打开终端,输入以下内容进行验证
bash
gcc --version
g++ --version
gdb --version
2.4 安装cmake
在MSYS2 MSYS
窗口运行
bash
pacman -S mingw-w64-ucrt-x86_64-cmake
- 验证安装:
Win+R
并输入cmd
打开终端,输入以下内容进行验证
首先检查路径对不对(一般是ucrt64\bin\cmake.exe
)
bash
where cmake
然后
bash
cmake --version
3 vscode配置文件
c_cpp_properties.json
bash
{
"configurations": [
{
"name": "GCC",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22000.0",
"compilerPath": "C:\\Users\\msys64\\ucrt64\\bin\\g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
launch.json
bash
{
"version": "2.0.0",
"configurations": [
{
"name": "C/C++: g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Users\\msys64\\ucrt64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
tasks.json
bash
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Users\\msys64\\ucrt64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always", // 彩色输出编译错误信息
"-g",
"${file}",
"${workspaceFolder}/include/*.cpp",
"-I",
"${workspaceFolder}/include",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}