Windows での,MSYS2 と GNU ツールチェーン類(gcc など)のインストール手順を説明する. MSYS2 は,ターミナル mintty とシェル bash と各種UNIX風コマンドの詰め合わせ.
MSYS2 には,MSYS, MINGW64, UCRT64 などのさまざまな環境がある (環境についての公式の説明は: https://www.msys2.org/docs/environments/).
このページでは,MSYS2 のベースと,MINGW64環境の LLVM(Clang, Flang, LLD, LLDB)とGNU ツールチェーン類 (gcc, g++, gfortran, gdb, make, ninja, ccache, svn 等) のインストール を行う.
【目次】
【関連する外部ページ】
MSYS2 の環境について(公式ページ): https://www.msys2.org/docs/environments/
MSYS2 は,ターミナル mintty とシェル bash と各種UNIX風コマンドの詰め合わせ. pacmanコマンドを使ってパッケージの追加もできる.UNIX風コマンドとpacmanコマンドが便利.
スタートメニューで,「MSYS2」の下の「MSYS2 MINGW64」を選ぶ.
echo $MSYSTEM echo $PATH echo $PKG_CONFIG_PATH
いま開いたmsysで次のコマンドを実行する
pacman -Syu
※ 質問には「y」+ Enter キー
スタートメニューで,「MSYS2」の下の「MSYS2 MINGW64」を選ぶ.
pacman -Su
※ 質問には「y」+ Enter キー
MINGW64
そのために,Windows で,コマンドプロンプトを管理者として実行
コマンドプロンプトを管理者として実行: 別ページ »で説明
call powershell -command "[System.Environment]::SetEnvironmentVariable(\"MSYSTEM\", \"MINGW64\", \"Machine\")"
そのために,Windows で,コマンドプロンプトを管理者として実行
コマンドプロンプトを管理者として実行: 別ページ »で説明
call powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";C:\msys64\mingw64\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")" call powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";C:\msys64\usr\local\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")" call powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";C:\msys64\usr\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")" call powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";C:\msys64\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")" call powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";C:\msys64\opt\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
そのために,新しく Windows のコマンドプロンプトを開き、次のコマンドを実行する.
エラーメッセージが出なければOK.
where bash where ls
MSYS2 に gcc, g++ (C言語, C++言語処理系) やその他のツールチェーンを,パッケージを使ってインストールする.
MSYS2 のインストールが終わっていること.
スタートメニューで,「MSYS2」の下の「MSYS2 MINGW64」を選ぶ.
次のコマンドを1つずつ実行.
※ 「Enter a selection (defaulit=all) という質問には・既定(デフォルト)のままでよいので、Enter キー
※ 「Proceed with installation? [Y/n] という質問には・インストールを続けたいので、Y, Enter キー
pacman -Sy --needed base-devel pacman -Sy --needed msys2-devel pacman -Sy --needed mingw-w64-x86_64-toolchain pacman -Sy --needed mingw-w64-x86_64-boost pacman -Sy --needed mingw-w64-x86_64-ninja pacman -Sy --needed mingw-w64-x86_64-libtool pacman -Sy --needed mingw-w64-x86_64-ccache pacman -Sy --needed mingw-w64-x86_64-clang pacman -Sy --needed mingw-w64-x86_64-flang pacman -Sy --needed mingw-w64-x86_64-lld pacman -Sy --needed mingw-w64-x86_64-lldb pacman -Sy --needed autoconf pacman -Sy --needed git pacman -Sy --needed subversion pacman -Sy --needed findutils pacman -Sy --needed ncurses-devel
「選択してください (デフォルト = all)」に対しては Enter キー
「インストールを行いますか? [Y/n] (Proceed with installation? [Y/n])」に対しては,y + Enter キー
コマンドを1つずつ実行するたびに、エラーメッセージが出ていないことを確認。
※ msys のパッケージは pacman -Ss <キーワード>で検索できる
Windows のコマンドプロンプトを開き、次のコマンドを実行する.
エラーメッセージが出なければOK.
where gcc where g++ where gfortran where gdb where make where ninja where ccache where svn where locate where clang where flang-new where lld where lldb
次のような結果が出るはず(必ずしも、ぴったりは一致しないでしょう.エラーメッセージが出なければ OK)
次のようなエラーメッセージが出るなどのときは、システム環境変数Pathの設定を確認し修正した後、Windows のコマンドプロンプトを開き直す。
ここではメモ帳 (notepad) を使っている.
Windows のコマンドプロンプトを開く. そして,次のように実行して,プログラムファイルを作る. そのファイル名は hello.c としている.
c: cd %HOMEPATH% notepad hello.c
#include<stdio.h> int main() { printf("Hello,World!\n"); printf("sizeof(size_t)=%ld\n", sizeof(size_t)); return 0; }
Windows のコマンドプロンプトを開き、次を実行.
結果として,「Hello,World!」「sizeof(size_t)=8」と表示されればOK.
del a.exe gcc hello.c .\a.exe
Windows のコマンドプロンプトを開き、次を実行.
結果として,「Hello,World!」「sizeof(size_t)=8」と表示されればOK.
del a.exe clang hello.c .\a.exe
ここではメモ帳 (notepad) を使っている.
Windows のコマンドプロンプトを開き,次のコマンドを実行する. ファイル名は hello.f90 としている.
c: cd %HOMEPATH% notepad hello.f90
program main print *, 'Hello,World!' stop end program main
x64 Native Tools コマンドプロンプトを使うこと.
結果として,「Hello,World!」と表示されればOK.
del hello.exe flang-new hello.f90 -o hello.exe .\hello.exe
実行結果例
msys2 の gdb 起動するとき,次のようなエラーメッセージが出ることがある.
ImportError: No module named libstdcxx.v6.printers /etc/gdbinit:6: Error in sourced command file: Error while executing Python code.
エラーメッセージから「gdbinit」に原因があると手掛かりが得られた. C:\msys64\etc\gdbinit をエディタで開く. すると,gcc のバージョンが間違っていることが分かる. 次のように書き直す.
もう一度 gdb を起動してみる.エラーメッセージが無くなることが分かる.