build設定

g++設定

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: g++ build active file",
			"command": "/usr/bin/g++",
			"args": [
				"-fdiagnostics-color=always",
        "-g",//行番号などの情報を渡し、コンパイル・実行時エラーの際に表示させる
        "-Wall",//警告を表示
        "-std=c++17",//C++17を使用
        "-O3",//最適化オプション
        "-fopenmp",//OpenMPを使用
        "-I/usr/include/eigen3",//Eigen3のヘッダファイルのパス
        "src/main.cpp",//パスを含めたファイル名
        "-I/usr/include/python3.10",//Python3.10のヘッダファイルのパス
        "-lpython3.10",//Python3.10のライブラリのパス
			],
			"problemMatcher": [
				"$gcc"
			],
            "group": {
                "kind": "build",
                "isDefault": true
            }
		}
	]
}

cmakeを使う場合の設定

{
    // See <https://go.microsoft.com/fwlink/?LinkId=733558>
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "process",
            "command": "make",
            "options": {
                "cwd": "${workspaceFolder}/build/"
            },
            "problemMatcher": {
                "base": "$gcc"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

実行設定

{
  "version": "0.2.0",
  "configurations": [
      {
          "name": "(gdb) Bash on Windows Launch",
          "type": "cppdbg",
          "request": "launch",
          "program": "${fileDirname}/../a.out",//デバッグ対象のファイルと同じディレクトリにあるa.outという実行可能プログラムを実行
          "cwd": "${fileDirname}",
          "externalConsole": true,
          "pipeTransport": {
              "debuggerPath": "/usr/bin/gdb",
              "pipeProgram": "/usr/bin/bash",
              "pipeArgs": ["-c"],
              "pipeCwd": "/"
          },
          "setupCommands": [
              {
                  "description": "Enable pretty-printing for gdb",
                  "text": "-enable-pretty-printing",
                  "ignoreFailures": true
              }
          ],

      }
  ]
}

参考サイト

WSL2+VSCodeでC++ファイルをビルド・デバッグする際のtasks.json及びlaunch.jsonの設定 - Qiita