Open2

C++VS Code & CMakeメモ

kale_corekale_core

vs codeに以下の機能拡張を入れる

  • C++
  • CMake
  • CMake Tools

ワークスペースとなるフォルダを作成してvs codeで開く
ctrl+shift+P CMake: Quick Startの案内に従う

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: cl.exe アクティブなファイルのビルド",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/nologo",
                "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${file}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "デバッガーによって生成されたタスク。"
        }
    ],
    "version": "2.0.0"
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(msvc) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            // Resolved by CMake Tools:
            "program": "${command:cmake.launchTargetPath}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [
                {
                    // add the directory where our target was built to the PATHs
                    // it gets resolved by CMake Tools:
                    "name": "PATH",
                    "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
                }
            ],
            "console": "integratedTerminal"
        }
    ]
}

参考
https://github.com/yoggy/study-vscode-cpp
https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/debug-launch.md#debug-using-a-launchjson-file
https://zenn.dev/husty/articles/b8098da2bf4803#vscode拡張機能の導入