VSCode RunAndDebug 插件配置指南

简介:VSCode RunAndDebug 是一款能够提供更详细 C++ 调试信息并支持中文路径的 VSCode 插件,以下是详细配置教程。

一、确定您的工作区

确定工作区是进行后续配置的前提,它是您在 VSCode 中开展项目工作的目录环境。

您可以通过以下两种方式确定工作区:

  1. 在 VSCode 中打开特定文件夹作为工作区
  2. 加载已有的 .code-workspace 工作区文件

注意:确保您有工作区的写入权限,以便创建后续所需的配置文件。

二、配置 tasks.json 文件

tasks.json 用于定义 VSCode 中的可执行任务,例如代码编译。

配置步骤:

  1. 在已确定的工作区中,新建 .vscode 文件夹
  2. 在该文件夹中创建 tasks.json 文件
  3. 将以下内容复制到文件中
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
            }
        }
    ]
}

重要说明:

三、配置 launch.json 文件

launch.json 用于配置调试相关设置,实现 VSCode 中的代码调试功能。

配置步骤:

  1. RunAndDebug.exe 下载到您的工作目录中
  2. .vscode 文件夹中创建 launch.json 文件
  3. 将以下内容复制到文件中
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"
        }
    ]
}

重要说明:

联系我们

如果您对本教程有任何疑问、意见或建议,欢迎通过以下方式联系我们:

  1. 电子邮箱:huifeidexiaogougou@126.com
  2. 在线反馈:https://m-code.top/feedback.html