【问题标题】:Debugging c++ built with a makefile in Visual Studio Code在 Visual Studio Code 中调试使用 makefile 构建的 c++
【发布时间】:2016-12-26 02:01:18
【问题描述】:

我有一个使用 makefile 构建的现有代码库,我想使用 Visual Studio Code 来运行它。

我首先使用 Visual Studio Code 打开我的项目目录。 然后,为了构建,我根据http://code.visualstudio.com/docs/languages/cpp 创建了一个任务:

{
    "version": "0.1.0",
    "command": "bash",
    "isShellCommand": true,
    "args":["-c", "cd build && make"]
}

效果很好。然后我下载了 C++ 扩展并创建了一个 launch.json:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "C++ Launch",
        "type": "cppdbg",
        "request": "launch",
        "targetArchitecture": "x64",
        "program": "${workspaceRoot}/build/myProgram",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "environment": [],
        "externalConsole": true,
        "linux": {
            "MIMode": "gdb"
        },
        "osx": {
            "MIMode": "lldb"
        },
        "windows": {
            "MIMode": "gdb"
        }
    },
    // attach here, which I don't care about
]
}

这个启动文件允许我使用内置调试器启动我的程序。我知道它可以工作,因为我看到所有符号文件都已加载,我可以暂停程序。

但是,VS Code 并没有“看到”我的源文件;当我暂停时它说

 Source /Unknown Source is not available.

我也无法在源代码中设置断点。我看到 some 符号被加载了,因为当我暂停执行时,我可以在调用堆栈上看到我的函数名称。

那么我错过了什么?我是否绝对必须按照他们在此处所说的 (http://code.visualstudio.com/docs/languages/cpp) 执行 g++ 任务,我必须手动输入所有包含路径和链接器输入?首先使用 makefile 的目的是不必做这些乏味的事情......

非常感谢任何知道如何处理 VS 代码的人。

【问题讨论】:

    标签: c++ macos makefile visual-studio-code


    【解决方案1】:

    您应该可以只使用tasks.jsonlaunch.json 进行调试。

    您确定在您的 makefile 中设置了 -g 选项吗?

    另一件事 - 您可以通过添加来让您的任务在启动时执行 "preLaunchTask": "bash" 给你的launch.json

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      在窗户上; Mingwgdb-g 参数在编译可执行文件时对于 c/c++ 扩展是必需的。 "preLaunchTask": "bash"launch.json 中不是必需的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-04
        • 1970-01-01
        • 1970-01-01
        • 2022-08-11
        相关资源
        最近更新 更多