1

我有两个问题。我刚刚安装了 VS 代码并设法让它编译 C 代码并显示输出。但我无法调试。当我添加断点和调试时,红色圆圈变灰。

我在 github 上读到添加 -g 标志会起作用

Q1。但是在哪里以及如何添加 -g标志?我还读到:

如何将编译标志 -g 添加到 make 文件中?

但它从我的头上掠过。

启动.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}/try.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
            "preLaunchTask": "echo",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

任务.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-Wall", "try.c", "-o", "try"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

我试图将from更改为args,但它也阻止了它的编译,这至少以前可以工作。如果我添加了,程序仍然没有调试。tasks.json-o-g-o

编辑:

Q2。另外还告诉我是否可以在tasks.json此处添加 C++ 的路径而不是 C?

因为我找不到 C 的路径。互联网上的教程是针对 C++ 的,他们告诉在那里设置 C++ 路径。但是我想编译 C 代码,尽管它们现在正在编译。

"includePath": [
                "${workspaceFolder}/**",
                "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++"
4

1 回答 1

3

您应该添加标志,而不是替换"-o"标志。

-o标志告诉编译器输出文件的名称。

所以改为有例如

"-Wall", "-g", "try.c", "-o", "try"
于 2018-08-25T05:34:44.473 回答