hack のためのネタ帳, etc,,,

vscode で C/C++ 開発を行う場合に vscode 上から build や debug を行う方法について。

まず最低限、以下の拡張が必要。

ほぼ何も考える必要が無い。
デバッグしたいファイルを開いてアクティブなタブにした状態で、おもむろにメニューの「Debug」→「Start Debugging F5」または左端の Debug ペイン(Shift+Ctrl+D)の上部にある▷(Start Debugging)アイコン、またはそのすぐ右のコンボボックスにある「Add Configuration...」もしくはさらにそのすぐ右にある⚙(Configure to fix 'launch.json')でデバッグを開始するだけで良い。
すると、コマンドパレットに
Select Environment
と表示されて、
.NET Core
C++ (GDB/LLDB)
Node.js
More...
とサジェスチョンが表示される。
ここで、「C++ (GDB/LLDB)」を選べばコマンドパレットに
Select Configuration
と表示されて、
gcc-7 build and debug active file
gcc-5 build and debug active file
gcc build and debug active file
Default Configuration
とサジェスチョンが表示される。
あとは「Default Configuration」以外から適当に選べば .vscode/launch.json と .vscode/task.json が自動生成され、ビルドタスクを実行した後、デバッガの開始までしてくれる。

ただし、まだ、現時点では若干詰め切れてない部分があるようだ。
もし .vscode/ が存在しなかった場合 .vscode/launch.json を生成した段階で停止してしまう。
この場合、メニューの「Terminal」→「Run Task」または「Terminal」→「Run Build Task... Ctrl+Shift+B」を選べば、
コマンドパレットに
Select the build task to run
と表示され、
C/C++: gcc-7 build and debug active file
C/C++: gcc-5 build and debug active file
C/C++: gcc build and debug active file
とサジェスチョンが表示される。
各項目の右端に表示される⚙(Configure Task)ってアイコンがをクリックすると task.json が生成される。
キーボードで操作する場合は、カーソルキーで項目を選択して TAB キーを叩くと⚙アイコンにフォーカスが移動するので、そこで ENTER を叩くと良い。

他にも、コマンドパレットから「C/C++: Build and Debug Active File」を実行する方法もある。
この場合もコマンドパレットに
Select Compiler
と表示されて、
gcc-7 build and debug active file
gcc-5 build and debug active file
gcc build and debug active file
とサジェスチョンが表示されるので以下同様。
ただし、この方法では .vscode/launch.json は生成されず .vscode/task.json のみが自動生成されて build が実施される。
しかし .vscode/ が存在しない場合は「Start Debugging F5」から開いた場合と同様 .vscode/task.json が生成されない。
このため、実行すべきタスクの定義が存在しない状態となるので、結果として何も起こらない。

生成される .vscode/launch.json と .vscode/task.json の組は以下の通り。
gcc のバージョンしていを必要とするような特別な理由がない限りは「gcc build and debug active file」を選んでおけば問題無い。
そうすればディストリビューションデフォルトの gcc が呼ばれる。

gcc build and debug active file

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": "gcc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "gcc build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}
task.json
{
    "tasks": [
        {
            "type": "shell",
            "label": "gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            }
        }
    ],
    "version": "2.0.0"
}

gcc-5 build and debug active file

gcc-7 build and debug active file


ここで自動生成される設定のポイントは、何と言っても、launch.json の "preLaunchTask": の設定により、デバッグ前に実行される task が指定してあるところだ。
なぜかこの雛形は「Add Configuration...」で出て来る一覧には登録されておらず、現時点で launch.json を開いて右下に出てくる「Add Configuration...」等から追加出来る設定には、この "preLanchTask": の設定がない。
という訳で launch.json, task.json が存在しない場合に上記の手順を踏む以外の方法で build と debug を面一で実行する設定を自動生成する方法を見つけることが出来なかった。


基本的に単一ファイルの時の設定と同じ手順を踏めばほぼ自動的に生成出来るが、task.json 用のビルドコードは単一ファイル用なので、そこは調整が必要となる。

しかし、ビルドのルールを task.json に書くのは面倒なので、素直に Makefile を書くのが吉だろう。
task.json への設定は make を呼び出すための極々簡素な物で構わない。
以下に示す程度の設定で充分だろう。
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "make",
            "command": "make",
        }
    ]
}
あとは適当な Makefile を書いておくだけで良い。
こちらも最低限と言う意味では以下のような簡素なもので充分だ。
CFLAGS=-g
all: hello
hello: hello.c sub.c

念のため補足しておくと、gdb でソースコードデバッグするためには gcc/g++ に -g オプションを付けてコンパイルする必要があるので CFLAGS, CXXFLAGS に追加しておくのを忘れてはいけない。

あと、launch.json の以下の部分は、
            "program": "${fileDirname}/${fileBasenameNoExtension}",
となっていると、現在アクティブになっているタブで開かれているファイルをデバッグしようとしてしまう。
分割コンパイル前提の場合は make でビルドされるバイナリの名称に合わせて例えば
            "program": "${fileDirname}/hello",
のように変更しておいた方が便利だろう。



公式ドキュメントは以下にあるのだが、少なくとも現状のバージョンだと読んでて色々と疑問を感じる。
Microsoft Store に登録されている WSL 用の Ubuntu は現在以下の3種類が存在する。 一番上のは確か 16.04 LTS だったような気がするので、とりあえず一番下のを選択。

wslpath コマンドを用いると、WSL の / へは \\wsl$\Ubuntu-18.04\ でアクセス可能である事がわかる。
ただし、Windows 側の cmd や powershell からこのパスにある gcc 等 WSL 側の実行ファイルを直接実行することは出来ないようだ。
実際に試してみた結果が以下となる。
>dir \\wsl$\Ubuntu-18.04\usr\bin\gcc
 ドライブ \\wsl$\Ubuntu-18.04 のボリューム ラベルがありません。
 ボリューム シリアル番号は 0000-0000 です

 \\wsl$\Ubuntu-18.04\usr\bin のディレクトリ

2019/05/21  01:08    <JUNCTION>     gcc [...]
               1 個のファイル                   5 バイト
               0 個のディレクトリ  326,304,342,016 バイトの空き領域
>\\wsl$\Ubuntu-18.04\usr\bin\gcc
'\\wsl$\Ubuntu-18.04\usr\bin\gcc' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。
2019-09-09: 追記
ネイティブなパスでも同様に直接の実行は不可能なようだ。
>dir %LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\usr\bin\gcc
 ドライブ C のボリューム ラベルがありません。
 ボリューム シリアル番号は 6E6F-F4F7 です

 C:\Users\kou\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\usr\bin のデ ィレクトリ

2019/09/09  11:39                 5 gcc
               1 個のファイル                   5 バイト
               0 個のディレクトリ  2,526,173,237,248 バイトの空き領域

>%LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\usr\bin\gcc
'C:\Users\kou\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\usr\bin\gcc' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。

Ubuntu の場合 WSL 側には最低限 build-essentials gdb が必要なので以下のように install しておく。
sudo apt update
sudo apt dist-upgrade
sudo apt install build-essentials gdb
もし gdb を入れ忘れてると後の方で、以下のようなエラーが発生する。
Visual Studio Code
&#8855; Unable to start debugging. Unable to establish a connection to GDB. The following message
   was writtern to stderr:
   
   /bin/bash: /usr/bin/gdb: No such file or directory
   
   See Output Window for details.
                                                       [Open Launch.json] [Cancel]

念のため wls に複数のディストリビューションが導入されていないか以下のコマンドで確認しておく事。
wslconfig /l
既定のディストリビューションが希望する物と異なる場合は以下のようにして変更しておく(DISTNAME は上の一覧で示された名前にする)。
wslconfig /s DISTNAME
もし既定のディストリビューションと異なるディストリビューションで利用したい場合は
「File」→「Preferences」→「Settings Ctrl+,」で Settings を開き右上の「Open Settings (JSON)」から以下の設定をしておけば良いはず。
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe",
    "terminal.integrated.shellArgs.windows": ["-d", "DISTNAME"],
2019-09-09: 追記、ここまで

あと、デフォルトシェルは「View」→「Command Paletts... Ctrl+Shift+P」から「Terminal: Select Default Shell」を実行して「wsl」に変更しておくのが良いだろう。


Ubuntu の場合とは異なり、いろいろと設定が必要だった。

まず、Ubuntu と同様にデバッグしたいファイルを開いてアクティブなタブにした状態で、おもむろにメニューの「Debug」→「Start Debugging F5」または左端の Debug ペイン(Shift+Ctrl+D)の上部にある▷(Start Debugging)アイコン、またはそのすぐ右のコンボボックスにある「Add Configuration...」もしくはさらにそのすぐ右にある⚙(Configure to fix 'launch.json')でデバッグを開始しようと試みても、エラーが発生し途中で止まってしまう。
今の場合、コマンドパレットに
Select Environment
と表示されて、
C++ (GDB/LLDB)
C++ (Windows)
Node.js
More...
とサジェスチョンが表示される。
ここで「C++ (GDB/LLDB)」を選んでも、以下に示す launch.json (これは「Default Configuration」の以下の設定であり、launch.json の右下に表示される「Add Configuration...」で追加できる「C/C++: (gdb) launch」と同じ設定)が生成される。
{
    // 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": "enter program name, for example ${workspaceFolder}/a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/path/to/gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

あらかじめ、「View」→「Command Pallet... Ctrl+Shift+P」から「C/C++: Edit Configurations (UI)」を開き、「Compiler path」を設定しておくと、.vscode/c_cpp_properties.json が生成される。
ただし、コンボボックスのプリセットで用意されてる /usr/bin/gcc, /usr/bin/g++, /usr/bin/cpp のどれを選んでも、右下に以下のエラーが表示される。
&#8855; "/usr/bin/gcc could not be dound. 'includePath' from
   c_cpp_properties.json will be used instead.

Source: C/C++ (Extension)

この状態だと「C++ (GDB/LLDB)」を選んだところでコマンドパレットに、
Select Configuration
と表示されて、
gcc build and debug active file
Default Configuration
が選択可能になる。
しかし、上述のエラーに加えて、Ubuntu のように gcc-5 とか gcc-7 のようにバージョン付きの項目は出て来てないところを鑑みると、具体的にコンパイラーを検出した結果からサジェスチョンが出ているわけではないようだ。
このため、いろいろと調整が必要となっている。

「gcc build and debug active file」で生成されるひな形は以下の内容。

gcc build and debug active file

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": "gcc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "\\usr\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "gcc build active file"
        }
    ]
}
task.json
{
    "tasks": [
        {
            "type": "shell",
            "label": "gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "/usr/bin"
            }
        }
    ],
    "version": "2.0.0"
}

これはこのままだと、以下のようなエラーが発生する。
Visual Studio Code
&#8855; The preLaunchTask 'gcc build active file' terminated with exit code -3.
                   [Debug Anyway] [Show Error] [Open launch.json] [Cancel]
この時の TERMINAL の内容は以下。
> Executing task: /usr/bin/gcc -g c:\Users\aki\Desktop\xxxx\hello.c -o c:\Users\aki\Desktop\xxxx\hello.exe <

The terminal shell CWD "\usr\bin" does not exist

Terminal will be reused by tasks, press any key to close it.
これは、task.json にある以下の設定によるもの。
            "options": {
                "cwd": "/usr/bin"
            }
これを削ると上記のエラーは解消するが、代わりに以下のようなエラーが新たに発生する。
Visual Studio Code
&#8855; The preLaunchTask 'gcc build active file' terminated with exit code 1.
                  [Debug Anyway] [Show Error] [Open launch.json] [Cancel]
この時の TERMINAL への出力は以下。
> Executing task: /usr/bin/gcc -g c:\Users\aki\Desktop\xxxx\hello.c -o c:\Users\aki\Desktop\xxxx\hello.exe <


gcc: error: c:\Users\aki\Desktop\xxxx\hello.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.
これは task.json の以下の部分が問題なので、
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
以下のように変更すれば解消はできる。
            "args": [
                "-g",
                "${fileBasename}",
                "-o",
                "${fileBasenameNoExtension}"
            ],

これでとりあえず、task.json は動く。
しかし、launch.json にも問題があるので、以下のようなエラーが発生する。
Visual Studio Code
&#8855; launch: program 'c:\Users\xxx\Desktop\hoge\hello.exe' dose not exist
                                            [Open launch.json] [Cancel]
これは launch.json の以下の箇所を
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
以下のように変更すれば通過出来る。
            "program": "${fileDirname}\\${fileBasenameNoExtension}",
しかし、今度は次のようなエラーが発生する。
Visual Studio Code
&#8855; Unable to start debugging. The value of miDebuggerPath is invalid
                                         [Open launch.json] [Cancel]
これは、launch.json の以下の部分が原因である。
            "miDebuggerPath": "\\usr\\bin\\gdb.exe",
しかし、以下のように変更しても問題は解決しない。
            "miDebuggerPath": "/usr/bin/gdb",
おそらくこれは、Windows 上の vscode が存在を確認しようとするが、WSL 上の gdb は Windows から見てここにはないからだろう。

これは、解決方法がよくわからなかった。
と言うか、WSL (Bash on Windows)用の configuration が別に用意されているのでそちらを利用したほうが良いようだ。

まず、.vscode/launch.json を開き、右下に表示される「Add Configuration...」のボタンから「C/C++: (gdb) Bash on Windows Launch」を選択する。
そうすると以下の設定が追加される。
        {
            "name": "(gdb) Bash on Windows Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "enter program name, for example ${workspaceFolder}/a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "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
                }
            ]
        },
前の設定は、動かないので捨てて問題ない。

このままデバッグを実行すると以下のようなエラーが発生する。
Visual Studio Code
&#8855; Unable to start debugging. Unexpected GDB output from command "-environment-cd
   C:/User/xxx/Desktop/hoge". C:/User/xxx/Desktop/hoge: No such file or directory.
                                                       [Open Launch.json] [Cancel]
これは launch.json の以下の設定が原因。
            "cwd": "${workspaceFolder}",
${workspaceFolder} には Windows 側のパスが入っているが、これは WSL 側の gdb で認識できないパスなので発生する。
結論から言うと、結局これは Windows 側の Current Working Directory なので WSL 側には関係ないのでどこでも良い。
ただし、この設定を削除したり、空文字列 "" にしたりすると、以下のようなエラーが発生してしまう。
Visual Stuio Code
&#8855; launch: property 'cwd' is missing or empty
                  [Open Launch.json] [Cancel]
従ってここは
            "cwd": "/",
または
            "cwd": "./",
のような確実に存在する場所を適当に設定しておく。

次に、以下の設定
            "program": "enter program name, for example ${workspaceFolder}/a.exe",
これは、見ての通り、適当な場所に変更するようにとの指示文が初期値として設定してあるので要変更である。
しかし、以下のように設定したのでは、Windows 側のパスを WSL 側に直接伝えてしまうためエラーとなってしまう。
            "program": "${workspaceFolder}/${fileBasenameNoExtension}",
結果は以下。
Visual Studio Code
&#8855; Unable to start debugging. Program path 'C:\User\xxx\Desktop\hoge/hello' is missing or
   invalid.

   GDB failed with message: C:/User/xxx/Desktop/hoge/hello: No such file or directory.

   This may occur if the process's executable was changed after the process was started, such as
   when installing an update. Try re-launching the application or restarting the machine.
                                                                     [Open Launch.json] [Cancel]

WSL 上のどこで gdb を実行しようとしているのかは、
以下のように pwd や ls を gdb に与えてみると確認できる。
            "program": "pwd",
            "cwd": "./",
            "program": "ls",
            "args": ["-C"],
            "cwd": "./",
それぞれの結果は以下の通り。
...
/
...
...
bin   dev  home  lib	media  opt   root  sbin  srv  tmp  var
boot  etc  init  lib64	mnt    proc  run   snap  sys  usr
...
cmd: "./" と設定しても WSL 上では / にいることがわかる。

WSL 上の cwd を ${workspaceFolder} にするためには
            "pipeTransport": {
                "debuggerPath": "/usr/bin/gdb",
                "pipeProgram": "${env:windir}\\system32\\bash.exe",
                "pipeArgs": ["-c"],
                "pipeCwd": "",
            },
と設定してある箇所の
                "pipeCwd": "",

                "pipeCwd": "${workspaceFolder}",
としてやればよい。
pwd を gdb に与えてみた結果は以下のようになる。
...
/mnt/c/Users/xxx/Desktop/hoge
...

あとは、program: を ./ にあるものとして以下のように与えれば晴れて WSL 上の gdb にコンパイル結果のバイナリを渡すことができる。
            "program": "./${fileBasenameNoExtension}",

最後にソースコードデバッガとして機能させるための設定。
この状態では、break point 等を設定した際、以下のようなエラーが表示される。
&#8855; Unable to open 'hello.c': Unable to read file (Error: File not found
   (\mnt\c\Users\xxx\Desktop\hoge\hello.c))
                                                          [Create File]
これは、先ほどとは逆で、WSL 上で実行された gdb はソースファイルを /mnt/c で始まるパスで要求してくるのだが、ホストの Windows 側で動いている vscode はこれを受け取ってもその場所にファイルはないので、Windows 本来の C:\ パスに直してそこにあるファイルを開く必要があるという状況。
そこでポイントとなるのが、以下のパラメータ。
            "sourceFileMap": {"/mnt/c": "C:\\"},
これを launch.json にの各設定に追加しておくことで、ブレークポイント等で止まった際に vscode 上で適切なファイルが表示されるようになる。

以上でデバッグに関する設定は終わり。

ただしこのままだと debug 前に自動で build が実行されない。
これは流石に面倒過ぎるので、「gcc build and debug active file」にあった以下の設定を拝借してくるとよい。
            "preLaunchTask": "gcc build active file"

ただし、task.json にコンパイル規則を書き起こすのは馬鹿馬鹿しく思えるので、Ubuntu のほうでも書いてるように、Makefile を書いて make に丸投げしてしまったほうが手早い。
例えば、以下のように設定を変更しておくことで launch 前に実行する task として make (これは task.json の "label": の値)を紐付けておく。
            "preLaunchTask": "make",
ここで呼び出される task に対応する設定は極めて簡素でかまわない。
例えば .vscode/task.json へは以下のように設定しておけば充分である。
        {
            "type": "shell",
            "label": "make",
            "command": "make",
        }
また、ここで make から呼び出される Makefile も以下のような簡素なもので構わない。
CFLAGS=-g
all: hello
hello: hello.c

もし、単一ファイル毎に実行ファイルを生成するようなケースなら、task.json を以下のように書いておくのも手だろう。
        {
            "type": "shell",
            "label": "make",
            "command": "make ${fileBasenameNoExtension}",
        }

以上の設定変更をまとめると以下のようになる。
        {
            "name": "(gdb) Bash on Windows Launch",
            "type": "cppdbg",
            "request": "launch",
            "preLaunchTask": "make",
            "sourceFileMap": {"/mnt/c": "C:\\"},
            "program": "./${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "./",
            "environment": [],
            "externalConsole": false,
            "pipeTransport": {
                "debuggerPath": "/usr/bin/gdb",
                "pipeProgram": "${env:windir}\\system32\\bash.exe",
                "pipeArgs": ["-c"],
                "pipeCwd": "${workspaceFolder}",
            },
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
挿入されたひな形からの変更箇所は以下の通り。

$ diff launch.json{~,}

$ diff -c launch.json{~,}



Remote Development 拡張を入れると vscode の左下に緑色で「><」の表示が現れるので、ここからコマンドパレットを呼び出し「Remote-WSL: Reopen Folder in WSL」を実行するのが第一歩。元に戻すには同様の操作で「Remote-WSL: Reopen Folder in Windows」を実行する。
ホストの Windows 側だけでなく、リモートの WSL 側にも C/C++ for Visual Studio Code 拡張をインストールしておく必要があるので、Remote-WSL した状態で「Extension Ctrl+Shift+X」から WSL 側に C/C++ for Visual Studio Code をインストールしておく。

以下、保留

2019-09-09: 追記
以下にまとめた 2019-09-09: 追記、おわり




保留
公式には無視されている存在のようだ

2019-09-09: 追記
普通にサポートされてた。 Integrated Terminal をデフォルトの PowerShell 以外に変更してしまうと、とことんトラブるが、PowerShell のままにしておけば、gcc/gdb ならほぼノートラブル。
ただし、launch.json に「"environment": [{"name": "PATH", "value":"C:\\Cygwin64\\bin"}],」を追加して cygwin1.dll へのパスを通しておく必要がある。
これさえなければ Ubuntu 並みと言ってよい。地味に簡単だった。

ただし、clang は難あり。
詳細は以下。 2019-09-09: 追記、ここまで


保留
と言うか、今のところ守備範囲外



多分、これが一番標準のはずなんだけど、vc 入ってるなら vscode じゃなくて Visual Studio で良くないかと?


参考


利用可能な変数

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

フリーエリア

管理人/副管理人のみ編集できます