軟件安裝
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
}
]
}
]
}