Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
Building Qt Desktop for Windows with MinGW: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
=Building Qt Desktop for Windows with MinGW= | [[Category:HowTo]] | ||
[toc align_right="yes" depth="2"] | |||
= Building Qt Desktop for Windows with MinGW = | |||
This chapter will describe some steps to build Qt using a windows host and the MinGW Toolchain. Since there is a 32bit and a 64bit MinGW that can be used to build your Desktop Qt you have to decide if you wanted to build Qt Libraries targetting a x86 (32bit) or a x64 (64bit) machine. Besides there is a possibility to cross build Qt on a 64bit host for a 32bit target and vice versa. | This chapter will describe some steps to build Qt using a windows host and the MinGW Toolchain. Since there is a 32bit and a 64bit MinGW that can be used to build your Desktop Qt you have to decide if you wanted to build Qt Libraries targetting a x86 (32bit) or a x64 (64bit) machine. Besides there is a possibility to cross build Qt on a 64bit host for a 32bit target and vice versa. | ||
Please look through the prerequisites before you start your work in order to make a definite step building your own Qt. Remark, this guidance here is only for your information. Any hints and comments you can read here are provided to help you to make your own steps with opensource software. There are many more possibilities to do the work. The below build process is only tested with Qt 4.7.4 on a windows 7 | Please look through the prerequisites before you start your work in order to make a definite step building your own Qt. Remark, this guidance here is only for your information. Any hints and comments you can read here are provided to help you to make your own steps with opensource software. There are many more possibilities to do the work. The below build process is only tested with Qt 4.7.4 on a windows 7 x64 host. | ||
Even so this guide has been created some time ago it is still applicable for Qt4. Only a few adaptations are required concerning the references to MinGW compilers. This has been tested on 64 bit windows 7 system for Qt 4.8.4 source building Qt for 64 bit targets. MinGW version was 4.7.2. | Even so this guide has been created some time ago it is still applicable for Qt4. Only a few adaptations are required concerning the references to MinGW compilers. This has been tested on 64 bit windows 7 system for Qt 4.8.4 source building Qt for 64 bit targets. MinGW version was 4.7.2. | ||
Additional questions may be posted | Additional questions may be posted "here":http://forum.qt.io/viewthread/19152/. | ||
==Do I need to build Qt?== | == Do I need to build Qt? == | ||
Perhaps not. The official Qt | Perhaps not. The official Qt SDK installer will work just fine. Follow these steps only if you want to learn how to make a cutom build or if you aim a x64 target. | ||
==Required Toolchains== | == Required Toolchains == | ||
To build Qt on your own windows desktop pc there is no wizzard needed. The main thing you want check is to choose the right toolsets that are able to build Qt from bottom up. Since there are many packages to find on the web you have to manage what package is chosen with caution. | To build Qt on your own windows desktop pc there is no wizzard needed. The main thing you want check is to choose the right toolsets that are able to build Qt from bottom up. Since there are many packages to find on the web you have to manage what package is chosen with caution. | ||
Line 25: | Line 29: | ||
* a tool to replace text in the makefiles (for the install step only) | * a tool to replace text in the makefiles (for the install step only) | ||
* a mingw32-make replacement to use all the cpu cores for building | * a mingw32-make replacement to use all the cpu cores for building | ||
* an application to unzip the tarfiles like | * an application to unzip the tarfiles like "7zip":http://www.7-zip.org/. | ||
* QtCreator 2.5 (or similiar, build process will be provided as well later) | To work with the newly created Qt you need also:<br />* QtCreator 2.5 (or similiar, build process will be provided as well later) | ||
=Prerequisites= | = Prerequisites = | ||
Although the build processes are very similar, please note that the ''cmd.exe'' shell build environment is slightly different for the '' | Although the build processes are very similar, please note that the ''cmd.exe'' shell build environment is slightly different for the ''PATH'' variable to find the right compiler toolchain. However, these tools are needed for both the build processes, 32 and 64bit: | ||
* Qt source code from | * Qt source code from "here&quot;:http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.tar.gz | ||
* Active Perl from | * Active Perl from "here&quot;:http://downloads.activestate.com/ActivePerl/releases/5.14.2.1402/. You need "''ActivePerl-5.14.2.1402-MSWin32-x64-295342.msi''". Any other perl might work too, this is the tested version. | ||
* jom.exe prebuilt from | * jom.exe prebuilt from "here&quot;:http://releases.qt.io/jom/jom.zip. | ||
* fart.exe prebuilt from | * fart.exe prebuilt from "here&quot;:http://sourceforge.net/projects/fart-it/files/fart-it/1.99b/. You need "''fart199b_win32.zip''". | ||
=Build Qt with MinGW for a x86 target= | = Build Qt with MinGW for a x86 target = | ||
This chapter describes on how to build the Qt opensource for a 32bit windows target. | This chapter describes on how to build the Qt opensource for a 32bit windows target. | ||
==Required toolchain== | == Required toolchain == | ||
* MinGW from the Qt | * MinGW from the Qt SDK, this is shipped i.e. with the SDK "Installer&quot;:http://qt.io/download. The toolchain itself runs on 32bit and 64bit windows. | ||
* The | * The SDK sourcecode used for this tutorial is Qt 4.7.4 (qt-everywhere-opensource-src-4.7.4.zip) and can be found "here&quot;:ftp://ftp.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.zip. | ||
==Filesystem setup== | == Filesystem setup == | ||
Prepare your filesystem for your own build process. There is a batchfile that can build everything automatically. As soon as there will be a place to download you will be noted. | Prepare your filesystem for your own build process. There is a batchfile that can build everything automatically. As soon as there will be a place to download you will be noted. | ||
Prepare a tree that contains the tools and the source trees (replace the c: | Prepare a tree that contains the tools and the source trees (replace the c:with whatever drive you need). It is recommended not to expand your computers path environment with the tools. Everything will take place in a single cmd.exe windows shell that has a path that fits your needs. | ||
For filesystem setup open windows explorer and create the following folders: | For filesystem setup open windows explorer and create the following folders: | ||
* set the root to c: | * set the root to c:–4.7.4 copy the mingw contents of the sdk into c:–4.7.4\mingw32_x86 | ||
* unzip the contents of the qt tar into c:–4.7.4\qt-everywhere-opensource-src-4.7.4 | |||
* unzip the contents of the qt tar into c: | * install or copy Perl into c:–4.7.4\tools\Perl | ||
* install or copy Perl into c: | * copy jom.exe into c:–4.7.4\tools\jom | ||
* copy jom.exe into c: | * copy fart.exe into c:–4.7.4\tools\fart | ||
* copy fart.exe into c: | * create a build directory for Qt under c:–4.7.4\4.7.4-qt-x86-build | ||
* create a build directory for Qt under c: | |||
* step into this build directory and create a file | * step into this build directory and create a file "''configure.cache''" with the following content (you may want to change for your needs):<br /><code>-platform win32-g++ -opensource<br />-debug -debug-and-release<br />-no-phonon<br />-fast<br />-nomake examples<br />-nomake demos<br />-no-dsp<br />-no-vcproj<br />-no-cetest<br />-no-s60<br />-qt-sql-odbc -qt-sql-sqlite -plugin-sql-odbc -plugin-sql-sqlite<br />-no-qt3support -no-opengl -no-openvg -no-incredibuild-xge<br /></code> | ||
==Configure your build tree== | == Configure your build tree == | ||
* If you are using MinGW (32bit) toolchain : Open a cmd.exe windows shell, ''cd'' into ''c: | * If you are using MinGW (32bit) toolchain : Open a cmd.exe windows shell, ''cd'' into ''c:–4.7.4\4.7.4-qt-x86-build'' and type:<br /><code><br />set PATH=C:–4.7.4\mingw32_x86\bin;C:–4.7.4\tools\Perl64\bin;C:–4.7.4\tools\jom;C:–4.7.4\tools\fart;<br />set PATH=PATH;c:32;<br />set LANG=en<br />c:–4.7.4\qt-everywhere-opensource-src-4.7.4\configure.exe -redo<br /></code> | ||
* If you are using MinGW-w64 (32bit) toolchain: | * If you are using MinGW-w64 (32bit) toolchain: | ||
** and, if you want to use Cmd-shell (cmd.exe windows shell), then ''cd'' into ''c: | ** and, if you want to use Cmd-shell (cmd.exe windows shell), then ''cd'' into ''c:5_windows_32bit'' and type:<br /><code><br />set PATH=C:-w64\32bit\bin;C:-perl\64bit\perl\bin;C:_tools\jom;C:_tools\fart;<br />set PATH=PATH;C:32;<br />set LANG=en<br />C:–4.7.4\qt-everywhere-opensource-src-4.7.4\configure.exe -redo<br /></code> | ||
** and, if you want to use [[MSYS2]]-shell, for 64bit (and 32bit) support based development, then follow this wiki page: [[MinGW-64- | ** and, if you want to use [[MSYS2]]-shell, for 64bit (and 32bit) support based development, then follow this wiki page: [[MinGW-64-bit]] | ||
After accepting the opensource license the configure command will then prepare qmake and the makefiles needed for the buildprocess. | After accepting the opensource license the configure command will then prepare qmake and the makefiles needed for the buildprocess. | ||
==Build Qt== | == Build Qt == | ||
Instead of mingw32-make we use jom. It is capable of distributing the work over a bunch of cpus being engaged by a Windows operating system. Type:<br /> or other commandline parameters if they fit better for you. After that the build process of Qt starts and you want to have a coffee or two. | Instead of mingw32-make we use jom. It is capable of distributing the work over a bunch of cpus being engaged by a Windows operating system. Type:<br /><code>jom /W /S -j4<code><br />or other commandline parameters if they fit better for you. After that the build process of Qt starts and you want to have a coffee or two. | ||
jom should finish with some warnings but without any error and you will have a pretty new build of the Qt Desktop library. Keep the shell open to make the next steps. | jom should finish with some warnings but without any error and you will have a pretty new build of the Qt Desktop library. Keep the shell open to make the next steps. | ||
==Installing the libraries.== | == Installing the libraries. == | ||
Installing the newly built libs is not straightforward because there is no | Installing the newly built libs is not straightforward because there is no "''make install''" way for the MinGW host. To install the Qt libraries and the tools of it there is some work to be done before. | ||
All the makefiles have | All the makefiles have "''install''" rules that install exactly to the folder that was used to build the whole library in. So installing into that folder doesn't make very much sense. All of the objectfiles still remain, and if you don't want to rebuild everything in the near future it is just a waste of diskspace. Installing for MinGW needs these ''install'' rules to be changed a bit. | ||
For that purpose you copied the ''fart.exe'' tool to the tools folder. ''fart.exe'' can be used like ''sed'' to find and replace text in textfiles. In the already open ''cmd.exe'' shell where you built the libs in you want to type the following: | For that purpose you copied the ''fart.exe'' tool to the tools folder. ''fart.exe'' can be used like ''sed'' to find and replace text in textfiles. In the already open ''cmd.exe'' shell where you built the libs in you want to type the following: | ||
Please note that after '' | </code><br />fart -c -i -r Makefile* $(INSTALL_ROOT)–4.7.4\4.7.4-qt-x86-build $(INSTALL_ROOT)–4.7.4\4.7.4-qt-x86<br />set INSTALL_ROOT=<br /><code> | ||
Please note that after ''INSTALL_ROOT='' must not be any character, not even a blank. | |||
This command will change<br /> into <br /> in every makefile and will set the shell variable to an empty string. Someone also could remove the variable at all, but | This command will change<br /></code>$(INSTALL_ROOT)–4.7.4\4.7.4-qt-x86-build</code><br />into<br /><code>$(INSTALL_ROOT)–4.7.4\4.7.4-qt-x86<code><br />in every makefile and will set the shell variable to an empty string. Someone also could remove the variable at all, but that's on your decision. | ||
After this jom can make the installation into c: | After this jom can make the installation into c:–4.7.4\4.7.4-qt-x86:<br /></code><br />jom /W /S -j4 install<br /><code> | ||
Since it is late now, someone probably wants to have a beer or two and wait for the installation to complete. After this there are some steps to do manually: | Since it is late now, someone probably wants to have a beer or two and wait for the installation to complete. After this there are some steps to do manually: | ||
</code><br />copy C:–4.7.4\mingw32_x86\bin\mingwm10.dll C:–4.7.4\4.7.4-qt-x86\bin<br />copy C:–4.7.4\mingw32_x86\bin\libgcc_s_dw2-1.dll C:–4.7.4\4.7.4-qt-x86\bin<br /><code> | |||
Create a config file that tells qmake about its new installation path. Create a textfile C:–4.7.4\4.7.4-qt-x86\bin\qt.conf:<br /></code><br />[Paths]<br />Prefix=C:/qt-4.7.4/4.7.4-qt-x86<br />Translations = translations<br /><code> | |||
=Build Qt with MinGW for a x64 (x86_64) target= | For now there is a dazzling new installation of your personal Qt build that can be found on your harddisk under C:–4.7.4\4.7.4-qt-x86. Go ahead and delete the build directory if you don't need it any more. If you want to be able to debug into the Qt sourcecode you might want to keep the sourcetree alive. | ||
= Build Qt with MinGW for a x64 (x86_64) target = | |||
This chapter describes on how to build the Qt opensource for a 64bit windows target. | This chapter describes on how to build the Qt opensource for a 64bit windows target. | ||
==Required toolchain== | == Required toolchain == | ||
* Information about the MinGW-w64 can be found on | * Information about the MinGW-w64 can be found on "the wiki on MinGW&quot;:http://wiki.qt.io/MinGW and in this wiki page [[MinGW-64-bit]]. The recommended download site of MinGW-builds provides the different flavors of the compiler. Developers of MinGW-builds have moved onto its newer successor project, [[MSYS2]], a complete opensource development solution/system, based on MinGW-w64 compilers/toolchains and MSYS. The MinGW-builds project is still supported. | ||
==Filesystem setup== | == Filesystem setup == | ||
Prepare your filesystem for your own build process. There is a batchfile that can build everything automatically. As soon as there will be a place to download you will be noted. | Prepare your filesystem for your own build process. There is a batchfile that can build everything automatically. As soon as there will be a place to download you will be noted. | ||
Prepare a tree that contains the tools and the source trees (replace the c: | Prepare a tree that contains the tools and the source trees (replace the c:with whatever drive you need). It is recommended not to expand your computers path environment with the tools. Everything will take place in a single cmd.exe windows shell that has a path that fits your needs. | ||
For filesystem setup open windows explorer and create the following folders: | For filesystem setup open windows explorer and create the following folders: | ||
* set the root to c: | * set the root to c:–4.7.4 copy the mingw contents of the zip into c:–4.7.4\mingw64_x64 | ||
* unzip the contents of the qt tar into c:–4.7.4\qt-everywhere-opensource-src-4.7.4 | |||
* unzip the contents of the qt tar into c: | * install or copy Perl into c:–4.7.4\tools\Perl | ||
* install or copy Perl into c: | * copy jom.exe into c:–4.7.4\tools\jom | ||
* copy jom.exe into c: | * copy fart.exe into c:–4.7.4\tools\fart | ||
* copy fart.exe into c: | * create a build directory for Qt under c:–4.7.4\4.7.4-qt-x64-build | ||
* create a build directory for Qt under c: | |||
* step into this build directory and create a file | * step into this build directory and create a file "''configure.cache''" with the following content (you may want to change for your needs):<br /></code><br />-platform win32-g++ -opensource<br />-debug -debug-and-release<br />-no-phonon<br />-fast<br />-nomake examples<br />-nomake demos<br />-no-dsp<br />-no-vcproj<br />-no-cetest<br />-no-s60<br />-qt-sql-odbc -qt-sql-sqlite -plugin-sql-odbc -plugin-sql-sqlite<br />-no-qt3support -no-opengl -no-openvg <s>no-incredibuild-xge<br /><code> | ||
<br />p. Do not be irritated when looking at the win32-g++ makespec. This makespec is also capable of building 64bit Qt. The ''PATH''</s> shell variable does currently only contain the path to MinGW64. So there will be no confusion about the compilers: | |||
== Configure your build tree == | |||
* Open a cmd.exe windows shell (Cmd-shell), ''cd'' into ''c:–4.7.4\4.7.4-qt-x64-build'' and type:<br /></code><br />set PATH=C:–4.7.4\mingw64_x64\bin;C:–4.7.4\tools\Perl64\bin;C:–4.7.4\tools\jom;C:–4.7.4\tools\fart;<br />set PATH=PATH;c:32;<br />set LANG=en<br />c:–4.7.4\qt-everywhere-opensource-src-4.7.4\configure.exe -redo<br /><code> | |||
* Open a cmd.exe windows shell (Cmd-shell), ''cd'' into ''c: | |||
* If you are using MinGW-w64 (64bit) toolchain: | * If you are using MinGW-w64 (64bit) toolchain: | ||
** and, if you want to use Cmd-shell (cmd.exe windows shell), then ''cd'' into ''c: | ** and, if you want to use Cmd-shell (cmd.exe windows shell), then ''cd'' into ''c:5_windows_64bit'' and type:<br /></code><br />set PATH=C:-w64\64bit\bin;C:-perl\64bit\perl\bin;C:_tools\jom;C:_tools\fart;<br />set PATH=PATH;C:32;<br />set LANG=en<br />C:–4.7.4\qt-everywhere-opensource-src-4.7.4\configure.exe -redo<br /><code> | ||
** and, if you want to use [[MSYS2]]-shell, for 64bit (and 32bit) support based development, then follow this wiki page: [[MinGW-64- | ** and, if you want to use [[MSYS2]]-shell, for 64bit (and 32bit) support based development, then follow this wiki page: [[MinGW-64-bit]] | ||
After accepting the opensource license the configure command will then prepare qmake and the makefiles needed for the buildprocess. | After accepting the opensource license the configure command will then prepare qmake and the makefiles needed for the buildprocess. | ||
==Build Qt== | == Build Qt == | ||
Instead of mingw32-make we use jom. It is capable of distributing the work over a bunch of cpus being engaged by a Windows operating system. Type:<br /> or other commandline parameters if they fit better for you. After that the build process of Qt starts and you want to have a coffee or two. | Instead of mingw32-make we use jom. It is capable of distributing the work over a bunch of cpus being engaged by a Windows operating system. Type:<br /></code>jom /W /S -j4</code><br />or other commandline parameters if they fit better for you. After that the build process of Qt starts and you want to have a coffee or two. | ||
jom should finish with some warnings but without any error and you will have a pretty new build of the Qt Desktop library. Keep the shell open to make the next steps. | jom should finish with some warnings but without any error and you will have a pretty new build of the Qt Desktop library. Keep the shell open to make the next steps. | ||
==Installing the libraries.== | == Installing the libraries. == | ||
Installing the newly built libs is not straightforward because there is no | Installing the newly built libs is not straightforward because there is no "''make install''" way for the MinGW host. To install the Qt libraries and the tools of it there is some work to be done before. | ||
All the makefiles have | All the makefiles have "''install''" rules that install exactly to the folder that was used to build the whole library in. So installing into that folder doesn't make very much sense. All of the objectfiles still remain, and if you don't want to rebuild everything in the near future it is just a waste of diskspace. Installing for MinGW needs these ''install'' rules to be changed a bit. | ||
For that purpose you copied the ''fart.exe'' tool to the tools folder. ''fart.exe'' can be used like ''sed'' to find and replace text in textfiles. In the already open ''cmd.exe'' shell where you built the libs in you want to type the following: | For that purpose you copied the ''fart.exe'' tool to the tools folder. ''fart.exe'' can be used like ''sed'' to find and replace text in textfiles. In the already open ''cmd.exe'' shell where you built the libs in you want to type the following: | ||
<code><br />fart -c -i -r Makefile* $(INSTALL_ROOT)–4.7.4\4.7.4-qt-x64-build $(INSTALL_ROOT)–4.7.4\4.7.4-qt-x64<br />set INSTALL_ROOT=<br /></code> | |||
Please note that after ''INSTALL_ROOT='' must not be any character, not even a blank. | |||
After this jom can make the installation into c: | This command will change<br /><code>$(INSTALL_ROOT)–4.7.4\4.7.4-qt-x64-build<code><br />into<br /></code>$(INSTALL_ROOT)–4.7.4\4.7.4-qt-x64</code><br />in every makefile and will set the shell variable to an empty string. Someone also could remove the variable at all, but that's on your decision. | ||
After this jom can make the installation into c:–4.7.4\4.7.4-qt-x64:<br /><code><br />jom /W /S -j4 install<br /></code> | |||
Since it is late now, someone probably wants to have a beer or two and wait for the installation to complete. After this there are some steps to do manually: | Since it is late now, someone probably wants to have a beer or two and wait for the installation to complete. After this there are some steps to do manually: | ||
<code><br />copy C:–4.7.4\mingw64_x64\bin\libgcc_s_sjlj-1.dll C:–4.7.4\4.7.4-qt-x64\bin<br /></code> | |||
The dual-target MinGW compiler adds an additional required dll to be copied. Following this guide step by step starting qmake will bring up an error message about missing libwinpthread-1.dll. | The dual-target MinGW compiler adds an additional required dll to be copied. Following this guide step by step starting qmake will bring up an error message about missing libwinpthread-1.dll. | ||
<code><br />copy C:–4.7.4\mingw64_x64\bin\libwinpthread-1.dll C:–4.7.4\4.7.4-qt-x64\bin<br /></code> | |||
Create a config file that tells qmake about its new installation path. Create a textfile C:–4.7.4\4.7.4-qt-x64\bin\qt.conf:<br /><code><br />[Paths]<br />Prefix=C:/qt-4.7.4/4.7.4-qt-x64<br />Translations = translations<br /></code> | |||
For now there is a dazzling new installation of your personal Qt build that can be found on your harddisk under C:–4.7.4\4.7.4-qt-x64. Go ahead and delete the build directory if you don't need it any more. If you want to be able to debug into the Qt sourcecode you might want to keep the sourcetree alive. | |||
= Building a cross Qt for x86 host and x64 target = | |||
=Links and references= | Coming soon… You may visit this wiki page: [[MinGW-64-bit]] | ||
= Links and references = | |||
* http://code.google.com/p/qt-msvc-installer/wiki/RelocationTricks | * http://code.google.com/p/qt-msvc-installer/wiki/RelocationTricks | ||
Line 177: | Line 186: | ||
* http://www.mixxx.org/wiki/doku.php/compiling_on_windows | * http://www.mixxx.org/wiki/doku.php/compiling_on_windows | ||
* http://en.wikipedia.org/wiki/Batch_file | * http://en.wikipedia.org/wiki/Batch_file | ||
* | * http://wiki.qt.io/Building_Qt_Documentation | ||
* http://pinyotae.blogspot.de/2010/11/building-64-bit-qt-47-using-mingw-w64.html | * http://pinyotae.blogspot.de/2010/11/building-64-bit-qt-47-using-mingw-w64.html | ||
* http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.tar.gz | * http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.tar.gz | ||
* http://qt.io/faq/answer/how_can_i_set_up_my_environment_for_building_qt_qt_applications_with_mingw | * http://qt.io/faq/answer/how_can_i_set_up_my_environment_for_building_qt_qt_applications_with_mingw | ||
Revision as of 10:41, 23 February 2015
[toc align_right="yes" depth="2"]
Building Qt Desktop for Windows with MinGW
This chapter will describe some steps to build Qt using a windows host and the MinGW Toolchain. Since there is a 32bit and a 64bit MinGW that can be used to build your Desktop Qt you have to decide if you wanted to build Qt Libraries targetting a x86 (32bit) or a x64 (64bit) machine. Besides there is a possibility to cross build Qt on a 64bit host for a 32bit target and vice versa.
Please look through the prerequisites before you start your work in order to make a definite step building your own Qt. Remark, this guidance here is only for your information. Any hints and comments you can read here are provided to help you to make your own steps with opensource software. There are many more possibilities to do the work. The below build process is only tested with Qt 4.7.4 on a windows 7 x64 host.
Even so this guide has been created some time ago it is still applicable for Qt4. Only a few adaptations are required concerning the references to MinGW compilers. This has been tested on 64 bit windows 7 system for Qt 4.8.4 source building Qt for 64 bit targets. MinGW version was 4.7.2.
Additional questions may be posted "here":http://forum.qt.io/viewthread/19152/.
Do I need to build Qt?
Perhaps not. The official Qt SDK installer will work just fine. Follow these steps only if you want to learn how to make a cutom build or if you aim a x64 target.
Required Toolchains
To build Qt on your own windows desktop pc there is no wizzard needed. The main thing you want check is to choose the right toolsets that are able to build Qt from bottom up. Since there are many packages to find on the web you have to manage what package is chosen with caution.
The following list will give an overview on the packages you need for your personal build of Qt opensource.
- The Qt Opensource Source Package with all the sourcecode
- a MinGW toolchain
- or a MinGW64 toolchain
- a Perl installation
- a tool to replace text in the makefiles (for the install step only)
- a mingw32-make replacement to use all the cpu cores for building
- an application to unzip the tarfiles like "7zip":http://www.7-zip.org/.
To work with the newly created Qt you need also:
* QtCreator 2.5 (or similiar, build process will be provided as well later)
Prerequisites
Although the build processes are very similar, please note that the cmd.exe shell build environment is slightly different for the PATH variable to find the right compiler toolchain. However, these tools are needed for both the build processes, 32 and 64bit:
- Qt source code from "here":http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.tar.gz
- Active Perl from "here":http://downloads.activestate.com/ActivePerl/releases/5.14.2.1402/. You need "ActivePerl-5.14.2.1402-MSWin32-x64-295342.msi". Any other perl might work too, this is the tested version.
- jom.exe prebuilt from "here":http://releases.qt.io/jom/jom.zip.
- fart.exe prebuilt from "here":http://sourceforge.net/projects/fart-it/files/fart-it/1.99b/. You need "fart199b_win32.zip".
Build Qt with MinGW for a x86 target
This chapter describes on how to build the Qt opensource for a 32bit windows target.
Required toolchain
- MinGW from the Qt SDK, this is shipped i.e. with the SDK "Installer":http://qt.io/download. The toolchain itself runs on 32bit and 64bit windows.
- The SDK sourcecode used for this tutorial is Qt 4.7.4 (qt-everywhere-opensource-src-4.7.4.zip) and can be found "here":ftp://ftp.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.zip.
Filesystem setup
Prepare your filesystem for your own build process. There is a batchfile that can build everything automatically. As soon as there will be a place to download you will be noted.
Prepare a tree that contains the tools and the source trees (replace the c:with whatever drive you need). It is recommended not to expand your computers path environment with the tools. Everything will take place in a single cmd.exe windows shell that has a path that fits your needs.
For filesystem setup open windows explorer and create the following folders:
- set the root to c:–4.7.4 copy the mingw contents of the sdk into c:–4.7.4\mingw32_x86
- unzip the contents of the qt tar into c:–4.7.4\qt-everywhere-opensource-src-4.7.4
- install or copy Perl into c:–4.7.4\tools\Perl
- copy jom.exe into c:–4.7.4\tools\jom
- copy fart.exe into c:–4.7.4\tools\fart
- create a build directory for Qt under c:–4.7.4\4.7.4-qt-x86-build
- step into this build directory and create a file "configure.cache" with the following content (you may want to change for your needs):
-platform win32-g++ -opensource<br />-debug -debug-and-release<br />-no-phonon<br />-fast<br />-nomake examples<br />-nomake demos<br />-no-dsp<br />-no-vcproj<br />-no-cetest<br />-no-s60<br />-qt-sql-odbc -qt-sql-sqlite -plugin-sql-odbc -plugin-sql-sqlite<br />-no-qt3support -no-opengl -no-openvg -no-incredibuild-xge<br />
Configure your build tree
- If you are using MinGW (32bit) toolchain : Open a cmd.exe windows shell, cd into c:–4.7.4\4.7.4-qt-x86-build and type:
<br />set PATH=C:–4.7.4\mingw32_x86\bin;C:–4.7.4\tools\Perl64\bin;C:–4.7.4\tools\jom;C:–4.7.4\tools\fart;<br />set PATH=PATH;c:32;<br />set LANG=en<br />c:–4.7.4\qt-everywhere-opensource-src-4.7.4\configure.exe -redo<br />
- If you are using MinGW-w64 (32bit) toolchain:
- and, if you want to use Cmd-shell (cmd.exe windows shell), then cd into c:5_windows_32bit and type:
<br />set PATH=C:-w64\32bit\bin;C:-perl\64bit\perl\bin;C:_tools\jom;C:_tools\fart;<br />set PATH=PATH;C:32;<br />set LANG=en<br />C:–4.7.4\qt-everywhere-opensource-src-4.7.4\configure.exe -redo<br />
- and, if you want to use MSYS2-shell, for 64bit (and 32bit) support based development, then follow this wiki page: MinGW-64-bit
- and, if you want to use Cmd-shell (cmd.exe windows shell), then cd into c:5_windows_32bit and type:
After accepting the opensource license the configure command will then prepare qmake and the makefiles needed for the buildprocess.
Build Qt
Instead of mingw32-make we use jom. It is capable of distributing the work over a bunch of cpus being engaged by a Windows operating system. Type:
jom /W /S -j4<code><br />or other commandline parameters if they fit better for you. After that the build process of Qt starts and you want to have a coffee or two.
jom should finish with some warnings but without any error and you will have a pretty new build of the Qt Desktop library. Keep the shell open to make the next steps.
== Installing the libraries. ==
Installing the newly built libs is not straightforward because there is no "''make install''" way for the MinGW host. To install the Qt libraries and the tools of it there is some work to be done before.
All the makefiles have "''install''" rules that install exactly to the folder that was used to build the whole library in. So installing into that folder doesn't make very much sense. All of the objectfiles still remain, and if you don't want to rebuild everything in the near future it is just a waste of diskspace. Installing for MinGW needs these ''install'' rules to be changed a bit.
For that purpose you copied the ''fart.exe'' tool to the tools folder. ''fart.exe'' can be used like ''sed'' to find and replace text in textfiles. In the already open ''cmd.exe'' shell where you built the libs in you want to type the following:
fart -c -i -r Makefile* $(INSTALL_ROOT)–4.7.4\4.7.4-qt-x86-build $(INSTALL_ROOT)–4.7.4\4.7.4-qt-x86
set INSTALL_ROOT=
Please note that after ''INSTALL_ROOT='' must not be any character, not even a blank.
This command will change<br />
$(INSTALL_ROOT)–4.7.4\4.7.4-qt-x86-build
into
$(INSTALL_ROOT)–4.7.4\4.7.4-qt-x86<code><br />in every makefile and will set the shell variable to an empty string. Someone also could remove the variable at all, but that's on your decision.
After this jom can make the installation into c:–4.7.4\4.7.4-qt-x86:<br />
jom /W /S -j4 install
Since it is late now, someone probably wants to have a beer or two and wait for the installation to complete. After this there are some steps to do manually:
copy C:–4.7.4\mingw32_x86\bin\mingwm10.dll C:–4.7.4\4.7.4-qt-x86\bin
copy C:–4.7.4\mingw32_x86\bin\libgcc_s_dw2-1.dll C:–4.7.4\4.7.4-qt-x86\bin
Create a config file that tells qmake about its new installation path. Create a textfile C:–4.7.4\4.7.4-qt-x86\bin\qt.conf:<br />
[Paths]
Prefix=C:/qt-4.7.4/4.7.4-qt-x86
Translations = translations
For now there is a dazzling new installation of your personal Qt build that can be found on your harddisk under C:–4.7.4\4.7.4-qt-x86. Go ahead and delete the build directory if you don't need it any more. If you want to be able to debug into the Qt sourcecode you might want to keep the sourcetree alive.
= Build Qt with MinGW for a x64 (x86_64) target =
This chapter describes on how to build the Qt opensource for a 64bit windows target.
== Required toolchain ==
* Information about the MinGW-w64 can be found on "the wiki on MinGW&quot;:http://wiki.qt.io/MinGW and in this wiki page [[MinGW-64-bit]]. The recommended download site of MinGW-builds provides the different flavors of the compiler. Developers of MinGW-builds have moved onto its newer successor project, [[MSYS2]], a complete opensource development solution/system, based on MinGW-w64 compilers/toolchains and MSYS. The MinGW-builds project is still supported.
== Filesystem setup ==
Prepare your filesystem for your own build process. There is a batchfile that can build everything automatically. As soon as there will be a place to download you will be noted.
Prepare a tree that contains the tools and the source trees (replace the c:with whatever drive you need). It is recommended not to expand your computers path environment with the tools. Everything will take place in a single cmd.exe windows shell that has a path that fits your needs.
For filesystem setup open windows explorer and create the following folders:
* set the root to c:–4.7.4 copy the mingw contents of the zip into c:–4.7.4\mingw64_x64
* unzip the contents of the qt tar into c:–4.7.4\qt-everywhere-opensource-src-4.7.4
* install or copy Perl into c:–4.7.4\tools\Perl
* copy jom.exe into c:–4.7.4\tools\jom
* copy fart.exe into c:–4.7.4\tools\fart
* create a build directory for Qt under c:–4.7.4\4.7.4-qt-x64-build
* step into this build directory and create a file "''configure.cache''" with the following content (you may want to change for your needs):<br />
-platform win32-g++ -opensource
-debug -debug-and-release
-no-phonon
-fast
-nomake examples
-nomake demos
-no-dsp
-no-vcproj
-no-cetest
-no-s60
-qt-sql-odbc -qt-sql-sqlite -plugin-sql-odbc -plugin-sql-sqlite
-no-qt3support -no-opengl -no-openvg no-incredibuild-xge
<br />p. Do not be irritated when looking at the win32-g++ makespec. This makespec is also capable of building 64bit Qt. The ''PATH''</s> shell variable does currently only contain the path to MinGW64. So there will be no confusion about the compilers:
== Configure your build tree ==
* Open a cmd.exe windows shell (Cmd-shell), ''cd'' into ''c:–4.7.4\4.7.4-qt-x64-build'' and type:<br />
set PATH=C:–4.7.4\mingw64_x64\bin;C:–4.7.4\tools\Perl64\bin;C:–4.7.4\tools\jom;C:–4.7.4\tools\fart;
set PATH=PATH;c:32;
set LANG=en
c:–4.7.4\qt-everywhere-opensource-src-4.7.4\configure.exe -redo
* If you are using MinGW-w64 (64bit) toolchain:
** and, if you want to use Cmd-shell (cmd.exe windows shell), then ''cd'' into ''c:5_windows_64bit'' and type:<br />
set PATH=C:-w64\64bit\bin;C:-perl\64bit\perl\bin;C:_tools\jom;C:_tools\fart;
set PATH=PATH;C:32;
set LANG=en
C:–4.7.4\qt-everywhere-opensource-src-4.7.4\configure.exe -redo
** and, if you want to use [[MSYS2]]-shell, for 64bit (and 32bit) support based development, then follow this wiki page: [[MinGW-64-bit]]
After accepting the opensource license the configure command will then prepare qmake and the makefiles needed for the buildprocess.
== Build Qt ==
Instead of mingw32-make we use jom. It is capable of distributing the work over a bunch of cpus being engaged by a Windows operating system. Type:<br />
jom /W /S -j4
or other commandline parameters if they fit better for you. After that the build process of Qt starts and you want to have a coffee or two.
jom should finish with some warnings but without any error and you will have a pretty new build of the Qt Desktop library. Keep the shell open to make the next steps.
Installing the libraries.
Installing the newly built libs is not straightforward because there is no "make install" way for the MinGW host. To install the Qt libraries and the tools of it there is some work to be done before.
All the makefiles have "install" rules that install exactly to the folder that was used to build the whole library in. So installing into that folder doesn't make very much sense. All of the objectfiles still remain, and if you don't want to rebuild everything in the near future it is just a waste of diskspace. Installing for MinGW needs these install rules to be changed a bit.
For that purpose you copied the fart.exe tool to the tools folder. fart.exe can be used like sed to find and replace text in textfiles. In the already open cmd.exe shell where you built the libs in you want to type the following:
<br />fart -c -i -r Makefile* $(INSTALL_ROOT)–4.7.4\4.7.4-qt-x64-build $(INSTALL_ROOT)–4.7.4\4.7.4-qt-x64<br />set INSTALL_ROOT=<br />
Please note that after INSTALL_ROOT= must not be any character, not even a blank.
This command will change
$(INSTALL_ROOT)–4.7.4\4.7.4-qt-x64-build<code><br />into<br />
$(INSTALL_ROOT)–4.7.4\4.7.4-qt-x64
in every makefile and will set the shell variable to an empty string. Someone also could remove the variable at all, but that's on your decision.
After this jom can make the installation into c:–4.7.4\4.7.4-qt-x64:
<br />jom /W /S -j4 install<br />
Since it is late now, someone probably wants to have a beer or two and wait for the installation to complete. After this there are some steps to do manually:
<br />copy C:–4.7.4\mingw64_x64\bin\libgcc_s_sjlj-1.dll C:–4.7.4\4.7.4-qt-x64\bin<br />
The dual-target MinGW compiler adds an additional required dll to be copied. Following this guide step by step starting qmake will bring up an error message about missing libwinpthread-1.dll.
<br />copy C:–4.7.4\mingw64_x64\bin\libwinpthread-1.dll C:–4.7.4\4.7.4-qt-x64\bin<br />
Create a config file that tells qmake about its new installation path. Create a textfile C:–4.7.4\4.7.4-qt-x64\bin\qt.conf:
<br />[Paths]<br />Prefix=C:/qt-4.7.4/4.7.4-qt-x64<br />Translations = translations<br />
For now there is a dazzling new installation of your personal Qt build that can be found on your harddisk under C:–4.7.4\4.7.4-qt-x64. Go ahead and delete the build directory if you don't need it any more. If you want to be able to debug into the Qt sourcecode you might want to keep the sourcetree alive.
Building a cross Qt for x86 host and x64 target
Coming soon… You may visit this wiki page: MinGW-64-bit
Links and references
- http://code.google.com/p/qt-msvc-installer/wiki/RelocationTricks
- http://stackoverflow.com/questions/4699311/how-to-install-qt-on-windows-after-building
- http://www.mixxx.org/wiki/doku.php/compiling_on_windows
- http://en.wikipedia.org/wiki/Batch_file
- http://wiki.qt.io/Building_Qt_Documentation
- http://pinyotae.blogspot.de/2010/11/building-64-bit-qt-47-using-mingw-w64.html
- http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.tar.gz
- http://qt.io/faq/answer/how_can_i_set_up_my_environment_for_building_qt_qt_applications_with_mingw