@mtbforq (たくみ 宮迫)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

vscodeでC言語のデバッグをしたいです。

vscodeでC言語のデバッグが出来るように設定したいのですが、エラーが発生し、デバッグ出来ません。
デバッグ出来るようにしたいです。

発生している問題・エラー

  ターミナルタブからビルドタスクの実行をし、その後実行タブからデバッグの開始をすると、以下のエラーが表示されます。

  タスク'C/C++; gcc.exe アクティブなファイルのビルドを見つけられませんでした。'



### 該当するソースコード
C2フォルダ
  helloworld.c
  .vscodeフォルダ
    launch.json
    tasks.json


helloworld.c
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

#include <stdio.h>

int main(void)
{
  printf("hello world!"); 
  return 0;
}

↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

launch.json
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

{
  // IntelliSense を使用して利用可能な属性を学べます。
  // 既存の属性の説明をホバーして表示します。
  // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "gcc.exe - アクティブ ファイルのビルドとデバッグ",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "C:\\MinGW\\bin",
      "environment": [],
      "externalConsole": true,
      "MIMode": "gdb",
      "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
      "setupCommands": [
        {
          "description": "gdb の再フォーマットを有効にする",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "C/C++: gcc.exe アクティブなファイルのビルド"
    }
  ]
}

↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

tasks.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": [
              "-g",
              "helloworld.c"
          ],
          "group": {
              "kind": "build",
              "isDefault": true
          }
      }
  ]
}

↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑




### 自分で試したこと

他サイトを見てtasks.jsonの"args"の中身の変更や、
launch.jsonの"miDebuggerPath"の変更等を試しましたがどれも上手くいかず、
サイトの説明通りに変更しているだけで具体的に何をやっているのか、変更点が正しい方向に向かっているのかすらわからないため、今回質問させていただきました。
msys2 64をインストールし、コマンドプロンプトでもgccコマンドが使える状態には設定しています。

よろしくお願いいたします。
0 likes

1Answer

まず、launch.jsonのpreLaunchTaskが正しくありません。
この場合、tasks.jsonのlabelである"echo"を指定する必要があります。

Note: The preLaunchTask setting is used to specify task to be executed before launch. Make sure it is consistent with the task.json file label setting.

また、tasks.jsonの方も、"args"で
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
が指定されていないのでa.exeができてしまい、
launch.jsonの"program"で起動できないです。

0Like

Comments

  1. @mtbforq

    Questioner

    ご紹介いただきましたサイトと、ご指摘の通り内容を変更したら無事デバッグすることが出来ました。
    ありがとうございます。

Your answer might help someone💌