【问题标题】:How to use GCC for compilation and debug on VSCode如何在 VSCode 上使用 GCC 进行编译和调试
【发布时间】:2019-03-03 13:23:25
【问题描述】:

我已经找到了几种使用 GCC 编译器调试 C 的不同方法,但是我希望在默认情况下进行调试。有什么方法可以通过我在 VSCode 中的 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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

【问题讨论】:

    标签: c gcc visual-studio-code


    【解决方案1】:

    将这些添加到您的 CFLAGS:-gdwarf-4 -g3

    为此,请运行以下命令:

    export CFLAGS="${CFLAGS} -gdwarf-4 -g3"
    

    查看this 链接了解更多信息,查看this 链接了解在launch.json 中运行的命令。

    【讨论】:

    • 感谢您的回答。可悲的是,它说“不允许使用属性 CFLAGS”。能否请您添加一个完整的示例?
    • 查看更新的答案。我不确定您是否以及如何做到这一点。老实说,我通常不使用像 VSCode 这样的专有编辑器。我使用开源替代品(非 Microsoft 版本,code-oss)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    • 2020-03-23
    • 1970-01-01
    相关资源
    最近更新 更多