【发布时间】: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