如何解决:"launch : program "executable.out"does not exist" in VS Code when debugging with gdb

How to solve : "launch : program "executable.out" does not exist" in VS Code when debugging with gdb

我正在学习 VScode 团队的教程: https://code.visualstudio.com/docs/cpp/config-wsl#_debug-helloworldcpp

我有 运行 并构建了另一个 c++ 项目。 它编译但项目在 运行 时崩溃,所以我决定调试它。

所以我想调试,我按照这个好教程的建议使用 gdb。 当我使用 "F5" 执行调试时,我有那个 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++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "executable.out",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

我修改了 "program" 部分以放置我的可执行文件 (executable.out) 的名称,它位于 "workspaceFolder"

所以我不明白我在执行 "F5" 时收到的错误消息:

launch : program "executable.out" does not exist

有人可以向我解释如何解决吗? 发这个问题之前想了很多。

非常感谢。 最好的问候

我假设您使用的是 Linux,因为您使用的是 g++ 编译器。 您是否将 cpp 文件编译为 "executable.out",例如

g++ main.cpp -o executable.out

你的 launch.json 配置对我来说很好。应该可以。

program中使用绝对路径:

"program": "${workspaceFolder}/executable.out"