本文を読み飛ばす

Build Qt 5.2.1 64 bit on Windows 7

まとめ

MinGW 64 bit を利用して 64 bit 版の Qt 5 をコンパイルし,これを使って簡単なプロジェクトのコンパイル及び他の PC へのデプロイ方法を紹介します.

前置き

Build Qt 5 from Git を読むのが最も効率がよいと思います.また,以下のポストなどを読む方がよいでしょう.

参考にしたブログなど

テスト環境

  • Windows 7 Professional 64 bit (日本語版)

  • MinGW 64 bit (gcc 5.2.0)

  • Strawberry perl (5.22.0.1, 64bit)

  • Git for Windows (2.6.3, 64bit)

  • Qt (5.2.1)

  • icu (56.1)

必要なソフトのインストール

既にインストールされているソフトを改めてインストールする必要はありませんが,もし,何らかの問題がある場合は,再インストールすると,問題が解決するかもしれません.

MinGW 64 bit のインストール

  1. mingw-w64 の Downloads にある Mingw-builds のリンクから,Web インストーラ,mingw-w64-install.exe をダウンロードして,実行.

  2. Architecture を x86_64 に変更.(Exception が seh になる.)

  3. Destination folder を C:\Program Files\mingw-w64\x86_64-5.2.0-posix-seh-rt_v4-rev1 から C:\mingw-w64\x86_64-5.2.0-posix-seh-rt_v4-rev1 に変更して,インストール.

Version

5.2.0

Architecture

x86_64

Threads

posix

Exception

seh

Build revision

1

Destination folder

C:\mingw-w64\x86_64-5.2.0-posix-seh-rt_v4-rev1

Git for Windows のインストール

  1. Downloading Git から Git-2.6.3-64-bit.exe をダウンロードして,実行.

  2. インストールオプションは何でも構わないが,例えば,以下の通りに設定してインストール.(但し,USERNAME は Windows のログイン名)

Destination Location

C:\Users\USERNAME\AppData\Local\Programs\Git

Components

Associate... の2つだけにチェック

Start Menu Folder

そのまま

Adjusting your PATH environment

Use Git from the Windows Command Prompt

Choosing the SSH executable

Use OpenSSH

Configuring the line ending conversions

Checkout as-is, commit as-is

Configuring the terminal emulator to use with Git Bash

Use MinTTY

Python 2.7.11 (64 bit) のインストール

  1. Python 公式ページPython のダウンロードページ から 64 bit 版の python-2.7.11.amd64.msi をダウンロードして,インストール.その際に,"Add python.exe to Path" のオプションをつけること.

Strawberry Perl のインストール

  1. Strawberry Perl の公式ページから Strawberry Perl 5.22.0.1 (64 bit) をダウンロードしてインストール.

Ruby のインストール

  1. Ruby-2.2.0 (x64) Microsoft Installer Package をダウンロードしてインストール.

環境変数の設定

ユーザ環境変数 PATH に少なくとも以下のものが同じ順序で並んでいることを確認する(但し,USERNAME は Windows のログイン名).これらの path は各ソフトのインストール時にシステム環境変数の PATH に設定されていることがあるが,以降は,システム環境変数からは消して,ユーザ環境変数に設定したものと見なす.

  • C:\Python27\;

  • C:\Python27\Scripts;

  • C:\Strawberry\c\bin;

  • C:\Strawberry\perl\site\bin;

  • C:\Strawberry\perl\bin;

  • C:\Users\USERNAME\AppData\Local\Programs\Git\cmd;

  • C:\Users\USERNAME\AppData\Local\Programs\Git\usr\bin;

  • C:\Qt\5.2.1\bin;

  • C:/icu/lib

ユーザ環境変数 LIB に

  • C:/icu/lib

を設定する.

ユーザ環境変数 INCLUDE に

  • C:/icu/include

を設定する.

他のソフトをインストールしている関係で何らかの開発環境が入っているとうまく動作しない可能性があります.

Qt 5 のダウンロード

コマンドプロンプトを開いて,以下の通り,qt5 をダウンロードする.Qt 5 の最新版は,5.6 ですが,ここでは問題なくデプロイできることを確認している 5.2.1 をコンパイルします.init-repository はかなり時間がかかるので,これを待ちながら,次に示す依存ライブラリ icu をインストールします.

mkdir src
cd src
git clone git://git.qt-users.jp/mirror/qt/qt5.git
cd qt5
git checkout -b 5.2.1 refs/tags/v5.2.1
perl init-repository --no-webkit

icu のダウンロード

icu は,Qt の多言語化機能で利用されている Unicode ライブラリで,翻訳機能を利用している場合は必須.

ICU - International Components for Unicode の Downloads から icu4c-56_1-src.zip をダウンロードして,先の src フォルダに展開.(例えば,%HOME%\src\icu

icu のコンパイル

スタートメニューの MinGW-W64 project の Run terminal でコマンドプロンプトを起動.(重要)

cd C:\Users\USERNAME\src\icu\source
set MSYSTEM=MINGW64 && sh runConfigureICU MinGW prefix=C:/icu
mingw32-make
mingw32-make install

Qt 5.2.1 (64 bit) のコンパイル

スタートメニューの MinGW-W64 project の Run terminal でコマンドプロンプトを起動.(重要)

cd C:\Users\USERNAME\src\qt5
set PATH=%PATH%;C:\Users\USERNAME\src\qt5\qtbase\bin;C:\Users\USERNAME\src\qt5\qtrepotools\bin;C:\Users\USERNAME\src\qt5\gnuwin32\bin
configure -prefix C:\Qt\5.2.1 -debug-and-release -opensource -confirm-license -platform win32-g++ -c++11 -opengl desktop -nomake tests -nomake examples
mingw32-make
mingw32-make install