【问题标题】:Unable to setup C++ debugging in VSCode; Debug type not recognized无法在 VSCode 中设置 C++ 调试;无法识别调试类型
【发布时间】:2020-04-16 23:01:36
【问题描述】:

我正在尝试设置 VSCode 以开始学习 C++。作为其中的一部分,我需要能够调试代码,所以我安装了带有 .vsix 文件的 C/C++ 扩展,以允许它添加 C++ 调试配置。但是,当我尝试设置配置时,我不认为 C++ 是环境的一个选项。只有节点、gdb 和 lldb。按照here 的说明,我在命令面板中没有看到任何关于 C++ 的建议。因此,我手动设置了任务、c_cpp_properties 和 launch.json 文件,并根据需要复制和粘贴并修改了路径。但是,VSCode 将 launch.json 中的 cppdbg 标记为不被识别为调试类型,并且将 stopAtEntry、环境、MIMode 和 miDebuggerPath 字段标记为“不允许属性 <...>”。如果我将其更改为 gdb,它会识别调试类型,但属性不允许错误仍然存​​在:

c_cpp_properties.json:

{
  "configurations": [
    {
      "name": "Win32",
      "includePath": ["${workspaceFolder}/**", "${vcpkgRoot}/x86-windows/include"],
      "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
      "windowsSdkVersion": "10.0.17763.0",
      "compilerPath": "C:\\dev\\tools\\mingw64\\bin\\g++.exe",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "intelliSenseMode": "${default}"
    }
  ],
  "version": 4
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "build hello world",
        "type": "shell",
        "command": "g++",
        "args": ["test.cpp"],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }

launch.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": "0.2.0",
    "configurations": [
      {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/test.exe",
        "args": [],
        "stopAtEntry": true,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "console": true,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\dev\\tools\\mingw64\\bin\\gdb.exe"
      }
    ]
  }

我使用的 VSCode 版本较旧,1.19。我编写代码的 HelloWorld/test.cpp 文件非常简单:

#include <iostream>
#include <string>

int main()
{
    std::cout << "Type your name" << std::endl;
    std::string name;
    std::cin >> name;
    std::cout << "Hello, " << name << std::endl;

    return 0;
}

谁能告诉我在这个过程中我缺少什么,因为到目前为止我在谷歌上找不到任何东西。

【问题讨论】:

    标签: c++ debugging visual-studio-code installation mingw-w64


    【解决方案1】:

    我收到了同样的错误消息,结果我的 launch.json 文件中列出了两种不同的配置。我以为我会在运行周期中选择一个,然后一切就可以了。结果我不得不注释掉未使用的启动配置以消除错误消息。 (gdb) Launch 很好,备注整个Linux版本lldb

    【讨论】:

      【解决方案2】:

      就我而言,我没有在 vscode 中安装 Microsoft C/C++ 扩展。我使用 docker 容器进行开发,我需要在附加到我的 docker 容器后安装此扩展。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-23
        相关资源
        最近更新 更多