LoginSignup
8
4

More than 3 years have passed since last update.

Mingw-w64のオフライン インストール

Last updated at Posted at 2020-06-02

g++をオフラインの端末にインストールしたので、その際のメモです。

ダウンロード&展開

Mingw-w64ダウンロードページの中段あたりにあるMinGW-W64 Online Installerの次にあるのが、オフライン インストール用のファイルです。
ダウンロード画面.png

ファイル名(ex: x86_64-posix-sjlj)はオンライン インストーラーを使用したときの選択項目(以下の画面)に対応しています。適切なものを選んでください(私はよく分かりません)。
online installer.png

ダウンロードしたファイルをオフラインの端末に移します。ファイルは7z形式で圧縮されていますので、7-zipで適当なフォルダーに展開してください(この記事ではD:\UserProgram\mingw64とします)。

パスを通す

このままだとパスが通っていないので、環境変数Pathにコンパイラーのパスを追加します。GUIでもできますが、Powershellを使った方法を紹介します。

ユーザー単位
> $envPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
> $envPath += ";D:\UserProgram\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin" #←g++.exeが含まれているパス
> [System.Environment]::SetEnvironmentVariable("Path", $envPath, "User")

端末単位で設定するには"User"を"Macine"に置き換えます。この場合、管理者権限が必要になります。

端末単位(要管理者権限)
> $envPath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
> $envPath += ";D:\UserProgram\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin" #←g++.exeが含まれているパス
> [System.Environment]::SetEnvironmentVariable("Path", $envPath, "Machine")

テスト

動くかどうか試してみましょう。
以下を適当なフォルダーに保存します(この記事ではD:\testとします)。

hello.cpp
#include <iostream>

int main()
{
    std::cout << "Hello!" << std::endl;
}

次にPowerShellで以下を実行します。

PowerShell
> cd D:\test
> g++ -g hello.cpp -o hello.exe #hello.exeが作成される
> ./hello.exe #作成したhello.exeを実行すると、"Hello!"と表示される
Hello!

最後のHello!が表示されれば成功です。やったぜフラン!!

参考

8
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
4