c++ - 在 VSCode 上使用 F5 进行调试失败,提示“无法建立与 GDB 的连接”
问题描述
当我按 F5 键在 Visual Studio Code 上运行 C++ 程序时,我收到消息
"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information."
我使用g++.exe
和 MinGW 进行编译。直到一个小时前,用 F5 键调试正常,我从来没有碰过launch.json
. 你能告诉我有什么问题吗?
下面是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": "g++.exe - アクティブ ファイルのビルドとデバッグ",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "gdb の再フォーマットを有効にする",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe アクティブなファイルのビルド"
}
]
}
下面是tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe アクティブなファイルのビルド",
"command": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "コンパイラ: C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe アクティブなファイルのビルド ver(1)",
"command": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "デバッガーによって生成されたタスク。"
}
]
}
下面是c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${vcpkgRoot}/x86-windows-static/include",
"C:\\Users\\SonicTheHedgehog\\Desktop\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
补充:我发现了一条错误信息launch.json
Property console is not allowed
并console
标有波浪线。
解决方案
查看此链接:https ://github.com/microsoft/vscode-cpptools/issues/2889
PowerShell 在内部控制台中运行(在 VSCode 中运行)存在一些问题。
我在 launch.json 中做了以下更改:
前:
"environment": [],
"externalConsole": **false**,
"MIMode": "gdb",
后:
"environment": [],
"externalConsole": **true**,
"MIMode": "gdb",
现在,我在 VSCode 之外的 cmd.exe 中看到了程序的输出。但是,调试器在 VSCode 中运行良好。
推荐阅读
- python - 在 PySpark 中导入用户定义的模块失败
- azure-devops - 从 CLI 获取 Azure Devops NPM 提要身份验证令牌
- openldap - ActiveMQ Artemis 无法针对 OpenLDAP 进行身份验证
- c# - 将 SupportedRuntime 设置为 4.6 后缺少装配错误 (System.Runtime.InteropServices.RuntimeInformation)
- php - 将 ACF 文件插入 CSS 伪元素
- javascript - 不要从 URL 中获取 GET 参数
- pandas - 哪个更好,多个文件的多个请求或单个文件的单个请求 S3?
- python - python随机选择什么都不选择
- firebase - 使用rest api在firebase实时数据库规则中授权uid
- node.js - 如何从控制器中提取成功和错误响应