无法在 VSCode 中设置 C++ 调试;无法识别调试类型

SVi*_*ill 8 c++ debugging installation mingw-w64 visual-studio-code

我正在尝试设置 VSCode 来开始学习 C++。作为其中的一部分,我需要能够调试代码,因此我使用 .vsix 文件安装了 C/C++ 扩展,以允许它添加 C++ 调试配置。但是,当我尝试设置配置时,我没有将 C++ 视为环境选项;仅节点、gdb 和 lldb。按照此处的说明,我在命令选项板中没有看到任何有关 C++ 的建议。因此,我手动设置任务、c_cpp_properties 和 launch.json 文件,复制、粘贴并根据需要修改路径。但是,VSCode 将 launch.json 中的 cppdbg 标记为未识别为调试类型,并将 stopAtEntry、environments、MIMode 和 miDebuggerPath 字段标记为“Property <...> not allowed”。如果我将其更改为 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
}
Run Code Online (Sandbox Code Playgroud)

任务.json:

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "build hello world",
        "type": "shell",
        "command": "g++",
        "args": ["test.cpp"],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }
Run Code Online (Sandbox Code Playgroud)

启动.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"
      }
    ]
  }
Run Code Online (Sandbox Code Playgroud)

我使用的 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;
}
Run Code Online (Sandbox Code Playgroud)

谁能告诉我在这个过程中我错过了什么,因为到目前为止我还没有在谷歌上找到任何东西。

use*_*415 6

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


zip*_*zit 1

我收到了同样的错误消息,结果发现我的 launch.json 文件中列出了两种不同的配置。我以为我只需在运行周期中选择一个,事情就会正常进行。结果我不得不注释掉未使用的启动配置以消除错误消息。 (gdb) Launch没问题,注释掉整个Linux版本lldb