Note. There is also another article that I wrote in compile from GIT a source with an automatic script in Windows. You can change it for Linux as the difference is shown in this post.
This article is constantly updated. If this helps you, please give him a thumbs up so I can know that he helps people and is not worthless.
If you have any comments or if you find typos, let me know so that I can fix them.
First, it doesn't matter if you want to compile a 32-bit or 64-bit version. The only difference is the command line shortcut that you need to select from Visual Studio, which initializes the various environment variables.
Let's start with this:
Download and Install Perl: Download Link
Download and Install Python: Download Link
Download and install the Windows SDK (maybe not necessary, but recommended) I use Windows 8, so this is the version I used: Download link , Otherwise, find the appropriate version for your Windows.
Download and install the DirectX SDK (perhaps necessary if you want to compile OpenGL) Download link
Download and extract jom to some folder (not required for Linux) (jom is a tool for compiling files with VS in parallel, there is a way to do it with nmake, but I'm not familiar with it) Download link
Download Qt Opensource and extract it, say, in C:\Qt\Qt5.6 , so now the qtbase folder can be found in C:\Qt\Qt5.6\qtbase .
Windows only: DO YOU REALLY WANT MANDATORY ARTICLES?
Usually, even if you choose static compilation, the compiler itself will still not merge its libraries statically. If you want your compiled source to be completely static with respect to the compiler (Visual Studio), you need to do this setup in QMAKE Qt files.
Browse to the file (starting from the Qt source directory), for versions older than 2012, just use the correct version everywhere (e.g. win32-msvc2015) :
but. For VS2012: qtbase \ mkspecs \ win32-msvc2012 \ qmake.conf
- b
. For VS2010: qtbase \ mkspecs \ win32-msvc2010 \ qmake.conf
from. For Qt 5.5.0 and later (with any version of VS): qtbase \ mkspecs \ common \ msvc-desktop.conf
and edit the following lines
QMAKE_CFLAGS_RELEASE = -O2 -MD QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi QMAKE_CFLAGS_DEBUG = -Zi -MDd
to
QMAKE_CFLAGS_RELEASE = -O2 -MT QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi QMAKE_CFLAGS_DEBUG = -Zi -MTd
Note. Qt 5.6+ has a -static-runtime configuration parameter that will do this for you. You may no longer need to do this manually for newer versions of Qt.
Start the terminal on Linux or Windows, start the Visual Studio terminals (which have the correct environment variables set, or, conversely, use vcvarsall.bat ). To start the command line and let it do it automatically for you, open "Start", "All Programs":
For versions of Windows prior to 8: find the Microsoft Visual Studio 201x folder and run the command prompt (either x86 for 32 bits or 64 for 64 bits).
For Windows 8: go to "Start", enter "cmd", and all available versions of the command line will appear. Select the appropriate version of Visual Studio (x86 for 32-bit or 64-bit for 64-bit).
Below is a screenshot of how this might look. Always try to choose a "native" if one exists.

9.
Note. The QMAKESPEC environment QMAKESPEC is considered invalid for Qt 5.8+ versions. Do not do this for new versions.
For dynamic linking (8 GB required)
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop
For dynamic linking without examples (2 GB required)
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -nomake examples -nomake tests Now the last command depends on what you want to compile. Just type configure -help and see what the available command-line parameters are.
For static binding (requires 70 GB, yes, this is crazy, it’s wiser not to create examples and demos).
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -static
For static snapping without examples (4 GB required, makes more sense).
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -static -nomake examples -nomake tests
Now it will take a minute or two, then use jom as follows (assuming it is extracted in C: \ Qt \ jom):
C:\Qt\jom\jom.exe -j 50
50 represents the number of cores you want to use. I use 50 because I have 8 threads, and only 8 will not completely occupy all the kernels, so it’s better, but not too greedy, as this may cause your system to not respond.
Note. The QMAKESPEC environment QMAKESPEC is considered invalid for Qt 5.8+ versions. Do not do this for new versions. For dynamic linking (8 GB required)
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop
For dynamic linking without examples (2 GB required)
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -nomake examples -nomake tests
The last command depends on what you want to compile. Just enter configure -help and see what options are available on the command line. For static binding (requires 70 GB, yes, this is crazy, it’s wiser not to create examples and demos).
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -static
For static snapping without examples (4 GB required, makes more sense).
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -static -nomake examples -nomake tests
Now it will take a minute or two, then use jom as follows (assuming it is extracted in C: \ Qt \ jom):
C:\Qt\jom\jom.exe -j 50
50 represents the number of cores you want to use. I use 50 because I have 8 threads, and only 8 will not completely occupy all the kernels, so it’s better, but not too greedy, as this may cause your system to not respond.
There is one small difference for Linux over Windows. It is recommended on linux for installation after compilation. Honestly, this is the only way that it works for me without any problems.
Run the following commands for Linux. Remember to replace the paths with the correct paths of your Qt source
export QMAKESPEC=linux-g++ export QTDIR=/home/username/Qt5.7/qtbase export PATH=/home/username/Qt5.7/qtbase/bin:$PATH
Note. The QMAKESPEC environment QMAKESPEC is considered invalid for Qt 5.8+ versions. Do not do this for new versions.
Suppose you want to install a compiled source in the directory /home/username/Qt5.7-install . In this case, add the following to any of the configuration commands below:
-prefix /home/username/Qt5.7-install
Warning : DO NOT install in the same source directory. This is simply wrong!
If -prefix not specified, a default path will be selected that matches /usr/local/ . I don’t like installing anything with root. I always prefer installing in my user folder, so reversibility and updates are not a problem.
The following are various possible configure commands, depending on what you want to do.
For dynamic linking (8 GB required)
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop
For dynamic linking without examples (2 GB required)
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -nomake examples -nomake tests
Now the last command depends on what you want to compile. Just type ./configure -help and see what command line options are available.
For static binding (requires 70 GB, yes, this is crazy, it’s wiser not to do examples and tests).
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -static
For static snapping without examples (4 GB required, makes more sense).
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -static -nomake examples -nomake tests
After execution make make make command
make -j 50
50 represents the number of cores you want to use. I use 50 because I have 8 threads, and only 8 will not completely occupy all the kernels, so it’s better, but not too greedy, as this may cause your system to not respond.
Wait 2 hours for the compilation to complete.
Clean up! You can save a lot of space by using this command for Windows: C:\Qt\jom\jom.exe clean And this command for linux: make clean
You can reduce the size of the compiled folder from 8 GB to 2.5 GB (for dynamic linking) and from 70 GB to 35 GB (for static linking).
To use this compiled version in Qt Creator:
- Launch Qt Creator
- Go to the "Tools", "Options"
- Select Build and Run in the list on the left.
- Click on the Qt Versions tab.
Click "Add" and select qmake from the folder in which qtbase is, so on top:
C: \ Qt \ Qt5.7 \ qtbase \ Bin \ qmake.exe
(or for Linux, select the path where you installed the compiled Qt source, which is equivalent to /home/username/Qt5.7-install/qtbase/bin/qmake in this tutorial)
- Click Apply
- Go to the Kits tab
- Click Add
- Give it a name, select the appropriate compiler (FOR VISUAL STUDIO EXPRESS DO NOT CHOOSE amd64 FOR 64-BIT, THIS DOES NOT WORK, CHOOSE x86_amd64 INSTEAD)
- Click OK.
Now just open the project and you will find that it asks you to select the kit that you added.
Enjoy :)