VSCode【fortranの設定】

参考にしました。

qiita.com

リンクのものは、WSL上にインストールしたコンパイラWindowsから使うことを目指したものですが、今回のトライはWSL上のインストールしたコンパイラをwslリモート接続のvscodeで設定しています。

Modern Fortranの設定

ctrl+,で設定を開く。"fortran"で検索し、Gfortran Executableにパスをインプット。パスはlinuxの記述でok

f:id:matsuo_san:20200320101206p:plain

usrをuserにしてはいけない(1敗)

FORTRAN IntelliSenseのインストール

fortran-language-serverをインストール。

 pip install fortran-language-server

さっきの設定画面でfortlsのpathを通します。fortlsのパスはwhichコマンドで探す。

 which fortls

f:id:matsuo_san:20200320151634p:plain

task.jsonの設定

こちらも参考にしつつ設定です。

my-web-site.iobb.net

ツールバーのターミナル→ビルドタスクの実行→テンプレートからtask.jsonを作ります。先人の方のものをコピペ。

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "gfortran debug",
            "type": "shell",
            "options": {
                "shell": {
                    "args": [],
                }
            },
            "command": "gfortran",
            "args": [
                "-g",
                "-O0",
                "-o",
                "/home/matsuo/${workspaceFolderBasename}/${fileBasenameNoExtension}.out",
                "${fileBasename}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            }
        },
        {
            "label": "My exec",
            "type": "shell",
            "command": "/home/matsuo/${workspaceFolderBasename}/${fileBasenameNoExtension}.out",
            "group": "test"
        }
    ]
}

コンパイル用にgfortran debugと実行用にMy execを用意しました。

launch.jsonの設定

gdbがインストールされたなかった?ようなのでとりあえずインストール

sudo apt install gdb

gdb設定後にデバッグ用のlaunch.jsonを作成。typeは”cppdbg”でないとダメ。

{
    // IntelliSense を使用して利用可能な属性を学べます。
    // 既存の属性の説明をホバーして表示します。
    // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387

    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/matsuo/${workspaceFolderBasename}/${fileBasenameNoExtension}.out",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/usr/bin/gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

デフォルトではブレークポイントの設定ができていなかったので、Extensionを追加しました。ただ入れるだけ。

Fortran Breakpoint Support - Visual Studio Marketplace

ひとまず、ここまででok