金子邦彦研究室インストールWindows の種々のソフトウェア(インストール)MinGW 64 バージョン 13.1 ucrt のインストール(gcc,g++,gfortran,gdb)(Windows 上)

MinGW 64 バージョン 13.1 ucrt のインストール(gcc,g++,gfortran,gdb)(Windows 上)

前準備

7-Zip 22.01 のインストール

Windows では, コマンドプロンプトを管理者として開き, 次のコマンドを実行することにより, 7-Zip 23.01 のインストールを行うことができる.

mkdir %HOMEPATH%\7zip
cd %HOMEPATH%\7zip
curl -O https://www.7-zip.org/a/7z2301-x64.exe
.\7z2301-x64.exe
powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\7-Zip\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"

MinGW64 のダウンロードとインストール

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. ダウンロードとインストール
    mkdir c:\mingw64
    cd c:\mingw64
    curl -L -O https://github.com/niXman/mingw-builds-binaries/releases/download/13.1.0-rt_v11-rev1/x86_64-13.1.0-release-win32-seh-ucrt-rt_v11-rev1.7z
    cd c:\
    "c:\Program Files\7-Zip\7z" x c:\mingw64\x86_64-13.1.0-release-win32-seh-ucrt-rt_v11-rev1.7z
    
  3. Windowsのシステム環境変数MSYSTEMを次のように設定
    MINGW64
    

    次のコマンドを実行

    powershell -command "[System.Environment]::SetEnvironmentVariable(\"MSYSTEM\", \"MINGW64\", \"Machine\")"
    
  4. Windowsのシステム環境変数Pathに次の5つを追加することにより,パスを通す

    次のコマンドを実行

    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\mingw64\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\mingw64\opt\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    
  5. bash, ls にパスが通っていることを確認する

    そのために,新しく Windowsコマンドプロンプトを開き、次のコマンドを実行する.

    エラーメッセージが出なければOK.

    where gcc
    where g++
    where gfortran
    where gdb
    

    [image]

gcc の動作確認

  1. エディタを起動

    ここではメモ帳 (notepad) を使っている.

    Windowsコマンドプロンプトを開く. そして,次のように実行して,プログラムファイルを作る. そのファイル名は hello.c としている.

    c:
    cd %HOMEPATH%
    notepad hello.c
    

    [image]
  2. いまメモ帳で開いたファイルを, 次のように編集する(コピー&ペーストしてください).そして保存する.
    #include<stdio.h>
    int main() {
        printf("Hello,World!\n");
        printf("sizeof(size_t)=%ld\n", sizeof(size_t));
        return 0;
    }
    

    [image]
  3. gcc の動作確認

    Windows のコマンドプロンプトを開き、次を実行.

    結果として,「Hello,World!」「sizeof(size_t)=8」と表示されればOK.

    del a.exe
    gcc hello.c
    .\a.exe
    

    [image]

gfortran の動作確認

  1. エディタを起動

    ここではメモ帳 (notepad) を使っている.

    Windowsコマンドプロンプトを開き,次のコマンドを実行する..png ファイル名は hello.f90 としている.

    c:
    cd %HOMEPATH%
    notepad hello.f90
    

    [image]
  2. いまメモ帳で開いたファイルを, 次のように編集する(コピー&ペーストしてください).そして保存する.
    program main
      print *, 'Hello,World!'
      stop
    end program main
    

    [image]
  3. 次のコマンドを実行

    結果として,「Hello,World!」と表示されればOK.

    del hello.exe
    gfortran hello.f90 -o hello.exe
    .\hello.exe
    

    実行結果例

    [image]