提供: いつきメモ
移動: 案内検索

MSYS2+VSCodeでC開発環境

MSYS2 + gcc環境

  • MSYS2 homepageからmsys2-x86_64なんとかこんとかをダウンロード。
  • インストールします
  • MSYS2 MinGW 64-bitを起動します
  • 次のコマンドを入力
pacman -Syu

インストールするか聞かれるのでYを選択

警告: terminate MSYS2 without returning to shell and check for updates again
警告: for example close your terminal window instead of calling exit

とか言われるので、Ctrl+Cで抜けて、window閉じて、MSYS2 MinGW 64-bitを再起動

もいっかい

pacman -Syu

を実行して、インストール。

次に、開発ツールをインストール。

pacman -S base-devel
pacman -S mingw-w64-x86_64-toolchain
pacman -S mingw64/mingw-w64-x86_64-cmake

これで、gcc -vとかが通るようになる

VSCodeの設定

setting.jsonにこんなのを書く

{
    "terminal.integrated.shell.windows": "C:\\msys64\\usr\\bin\\bash.exe",
    "terminal.integrated.env.windows": {
        "MSYSTEM": "MINGW64",
        "CHERE_INVOKING": "1"
    },
    "terminal.integrated.shellArgs.windows": [
        "--login"
    ],
    "terminal.integrated.cursorStyle": "line"
}

ディレクトリをVSCodeで開いて、Edit "includePath settingで

        {
            "name": "Win32",
            "includePath": [
                "C:/msys64/mingw64/include/c++/6.2.0",
                "C:/msys64/mingw64/x86_64-w64-mingw32/include",
                "${workspaceRoot}"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "path": [
                    "C:/msys64/mingw64/include/c++/6.2.0",
                    "C:/msys64/mingw64/x86_64-w64-mingw32/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }

こんなのを書く

あとは、makeをCtrl+Shift+Bに割り当てたら、大体できる