簡體   English   中英

無法在 VSCode 中設置 C++ 調試; 無法識別調試類型

[英]Unable to setup C++ debugging in VSCode; Debug type not recognized

我正在嘗試設置 VSCode 以開始學習 C++。 作為其中的一部分,我需要能夠調試代碼,所以我安裝了帶有 .vsix 文件的 C/C++ 擴展,以允許它添加 C++ 調試配置。 但是,當我嘗試設置配置時,我沒有將 C++ 視為環境選項; 只有節點、gdb 和 lldb。 按照此處的說明,我在命令面板中沒有看到任何關於 C++ 的建議。 因此,我手動設置了任務、c_cpp_properties 和 launch.json 文件,並根據需要復制、粘貼和修改路徑。 但是,VSCode 將 launch.json 中的 cppdbg 標記為未識別為調試類型,以及字段 stopAtEntry、environments、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
}

任務.json:

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

啟動.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;
}

誰能告訴我在這個過程中我遺漏了什么,因為到目前為止我還沒有在谷歌上找到任何東西。

我有同樣的錯誤消息,結果我的 launch.json 文件中列出了兩個不同的配置。 我以為我只會在運行周期中選擇一個,一切都會正常工作。 結果我不得不注釋掉未使用的啟動配置以消除錯誤消息。 (gdb) Launch ,注釋掉整個 Linux 版本lldb

就我而言,我沒有在 vscode 中安裝 Microsoft C/C++ 擴展。 我使用 docker 容器進行開發,我需要在附加到我的 docker 容器后安裝這個擴展。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM