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

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

本文关键字:调试 类型 识别 设置 VSCode C++      更新时间:2023-10-16

我正在尝试设置VSCode以开始学习C++。作为其中的一部分,我需要能够调试代码,所以我安装了带有.vsix文件的C/C++扩展名,以允许它添加C++调试配置。然而,当我尝试设置配置时,我并不认为C++是环境的一个选项;只有node、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
}

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;
}

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

在我的案例中,我没有在vscode中安装Microsoft C/C++扩展。我使用docker容器进行开发,在连接到我的docker容器后,我需要安装这个扩展。

我收到了同样的错误消息,结果发现我的launch.json文件中列出了两种不同的配置。我以为我会在跑步周期中选择一个,一切都会好起来的。事实证明,我不得不指出未使用的启动配置,以消除错误消息。(gdb) Launch很好,指出了整个Linux版本lldb