软件安装
1、从 https://winlibs.com/#download-release 下载MinGW版本(六十四位版本、三十二位版本--数字居然是敏感词汇) 比如:GCC 13.1.0 (with POSIX threads) + LLVM/Clang/LLD/LLDB 16.0.5 + MinGW-w版本 11.0.0 (UCRT) - release 5
2、解压到指定目录下,比如:D:\Win10Sys\MinGW
3、下载VSCode,安装到:D:\Win10Sys\VSCode
4、设置VSCode插件位置(由于C盘会满),比如:D:\Win10Sys\VSCodeExt,在 VScode 自动更新、重启时确保找到正确的扩展路径
mklink/D % USERPROFILE%.vscode\extensions D:\Win10Sys\VSCodeExt
软件配置
1、目录下建立.vscode 2、.vscode\tasks.json,如下:
{
"version": "2.0.0",
"tasks": [
{
"label": "cppbuild",
"type": "cppbuild",
"command": "D:/Win10Sys/MinGW/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-static",
"-g",
"${fileDirname}/${fileBasenameNoExtension}.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
]
}
对于TDMGCC,args中可以不加-static;对于winlib下必须增加。这样配置,才可以执行调试(原因是不想将多个版本的MinGW都加到PATH中)
3、.vscode\lauch.json,如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "2.0.0",
"configurations": [
{
"name": "C++ Launch GDB",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "xXX",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "cppbuild",
"MIMode": "gdb",
"miDebuggerPath": "D:/WinSys/MinGW/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
}
]
}
]
}