简介:VSCode RunAndDebug 是一款能够提供更详细 C++ 调试信息并支持中文路径的 VSCode 插件,以下是详细配置教程。
确定工作区是进行后续配置的前提,它是您在 VSCode 中开展项目工作的目录环境。
您可以通过以下两种方式确定工作区:
.code-workspace
工作区文件注意:确保您有工作区的写入权限,以便创建后续所需的配置文件。
tasks.json 用于定义 VSCode 中的可执行任务,例如代码编译。
.vscode
文件夹tasks.json
文件{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "Build with GBK",
"command": "cmd",
"args": [
"/c",
"chcp 936>nul && \"C:\\Mingw64\\bin\\g++.exe\" -fdiagnostics-color=always -g \"${file}\" -o \"${fileDirname}\\${fileBasenameNoExtension}.exe\""
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
C:\\Mingw64\\bin\\g++.exe
替换为您实际的 Mingw64 编译器路径launch.json 用于配置调试相关设置,实现 VSCode 中的代码调试功能。
.vscode
文件夹中创建 launch.json
文件{
"version": "0.2.0",
"configurations": [
{
"name": "Debug with GBK",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\RunAndDebug.exe",
"args": ["${file}"], // 将当前文件路径作为参数传递给RunAndDebug.exe
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build with GBK"
}
]
}
C:\\Mingw64\\bin\\gdb.exe
替换为您实际的 gdb 路径preLaunchTask
值应与 tasks.json 中的 label
值一致如果您对本教程有任何疑问、意见或建议,欢迎通过以下方式联系我们: