0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VSCodeでWSLを使いながらC++を扱うための設定メモ

Last updated at Posted at 2020-06-13

自分用のメモです。下記の記事を参考にしました。感謝いたします。
一部の設定値を変えています。
(https://qiita.com/2019Shun/items/5ab290a4117a00e373b6)

環境
OS:Windows10 Pro
バージョン: 2004(OSビルド 19041.329)

Visual Studio Code
バージョン: 1.46.0

WSL
OS:Ubuntu18.04.4
aptの更新後、build-essentialとgdbをインストール

ワークスペース内の.vscodeに配置するjsonファイルと中身
下記3つ
c_cpp_properties.json
launch.json
tasks.json

c_cpp_properties.json
{
    "configurations": [
      {
        "name": "WSL",
        "intelliSenseMode": "gcc-x64",
        "compilerPath": "/usr/bin/gcc",
        "includePath": ["${workspaceFolder}/**"],
        "defines": [],
        "cStandard": "c11",
        "cppStandard": "c++17"
      }
    ],
    "version": 4
}

[2020/06/16 自分用に追記]
"program""args" の設定値に${fileBasenameNoExtension}を使用した。(現在開いているファイル名から拡張子を除いたもの)
[2020/06/16 自分用に追記ここまで]

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Bash on Windows Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${command:extension.vscode-wsl-workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": ["<", "${command:extension.vscode-wsl-workspaceFolder}/${fileBasenameNoExtension}.in"],
            "stopAtEntry": false,
            "cwd": "${command:extension.vscode-wsl-workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "pipeTransport": {
                "debuggerPath": "/usr/bin/gdb",
                "pipeProgram": "${env:windir}\\system32\\bash.exe",
                "pipeArgs": ["-c"],
                "pipeCwd": "/"
            },
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "sourceFileMap": {
                "${command:extension.vscode-wsl-workspaceFolder}": "${workspaceFolder}"
            },

        }
    ]
}

[2020/06/16 自分用に追記]
"args" の設定値に${fileBasenameNoExtension}を使用した。(現在開いているファイル名から拡張子を除いたもの)
[2020/06/16 自分用に追記ここまで]

tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "options": {
                "shell": {
                    "executable": "C:\\Windows\\System32\\wsl.exe",
                }
            },
            "command": "g++",
            "args": [
                "-std=gnu++1y",
                "-g",
                "-O0",
                "-I/opt/boost/gcc/include",
                "-L/opt/boost/gcc/lib",
                "-o",
                "`wslpath",
                "'${workspaceFolder}\\${fileBasenameNoExtension}.exe'`",
                "`wslpath",
                "'${file}'`",
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

以上。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?