当我按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
用波浪线标记。
发布于 2021-02-25 17:38:55
我建议使用不同的基于编译器的扩展,例如代码运行器等,有时,扩展是visual studio代码中的兼容性问题。当我开始使用visual studio代码时,我也遇到了同样的问题。
发布于 2021-11-10 06:16:25
请查看此链接:https://github.com/microsoft/vscode-cpptools/issues/2889
在内部控制台中运行(在VSCode中运行)时,PowerShell会出现一些问题。
我在launch.json中做了以下更改:
之前:
"environment": [],
"externalConsole": **false**,
"MIMode": "gdb",
之后:
"environment": [],
"externalConsole": **true**,
"MIMode": "gdb",
现在,我在VSCode之外的cmd.exe中看到了程序的输出。但是,调试器在VSCode中运行得很好。
https://stackoverflow.com/questions/66365840
复制相似问题