【问题标题】:GDB debugger does not work on WSL mdoe on VS codeGDB 调试器不适用于 VS 代码上的 WSL mdoe
【发布时间】:2022-11-05 02:59:40
【问题描述】:

我已经开始在 VS 代码上使用 WSL,所以我可以习惯 linux 命令。我遇到的一个问题是调试器根本不工作,我收到了这个错误。我也在使用 g++ 编译器,它是最新的。

我试图更改launch.json 中的文件名,但这不起作用。如果需要更多图片,我可以提供。我只想解决这个问题,这样我就可以专注于我的大学作业而不是管理工作:)) 另外,这是我的 launch.json 文件[![在此处输入图像描述]

{
    "configurations": [
        {
            "name": "C/C++: g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ],
    "version": "2.0.0"
}```

【问题讨论】:

  • 在 WSL 中安装 g++,您目前在 WSL 中使用来自 Windows (MinGW) 的 g++(大多数 Windows 程序在 WSL 中可用)。
  • edit 将您的文本图像转换为实际文本。 See here 为什么。
  • @Holt 我将它安装在 ubuntu 和 WSL 中 VS 代码上的必要扩展
  • @AlexandruMititelu 删除 launch.json 然后让 VS Code 重新创建它。就像现在一样,您的 launch.json 是为 Windows 制作的。
  • 我删除了文件,现在 VS 代码告诉我同样的事情:启动程序不存在

标签: c++ debugging installation gdb g++


【解决方案1】:

它终于奏效了!由于找不到任何答案,我决定卸载 WSL 和我的 linux 发行版,然后重新从头开始整个过程​​。 以下是命令提示符的命令:

卸载: 卸载 app/linux 发行版: winget uninstall --id <Distro.name> 列出所有发行版:wsl -l

安装: <distro.name>(在我的例子中,我只是输入了 Ubuntu)

初始化: sudo apt-get 更新 sudo apt-get 升级 sudo apt-get install build-essential gdb

然后你转到 VS 代码,在终端的右上角(终端的快捷方式是 SHIFT + 1 之前的按钮),单击 + 图标以查看你拥有的不同终端。您选择 WSL 或可能会出现发行版的名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 2018-07-22
    • 2015-07-06
    • 2020-10-01
    • 2018-11-20
    相关资源
    最近更新 更多