1

2 つの質問があります。VSコードをインストールしたところ、Cコードをコンパイルして出力を表示することができました。しかし、私はデバッグすることができません。ブレークポイントを追加してデバッグすると、赤い丸が灰色になります。

-g フラグを追加すると機能することを github で読みました

Q1. -gしかし、フラグを追加する場所と方法は ? 私も読んだ:

コンパイル フラグ -g を make ファイルに追加する方法は?

しかし、それは私の頭の上を通り過ぎました。

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}/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
            }
        }
    ]
}

からに変更しようとし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