Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Note: There's also another article I wrote to <a href="https://blog.afach.de/?page_id=399" rel="noreferrer">compile from GIT source here with an automated script</a> on Windows. You may modify it for Linux as the difference is shown in this post.</p> <p>This article is continuously being updated. If this helps you, please give it a "thumbs up" so that I could know that it's helping people and not being useless.</p> <p>If you have any comments or you found typos, please let me know so that I can fix them.</p> <p>First thing, it doesn't matter whether you want to compile 32 or 64 bit version. The only difference is the command prompt shortcut that you have to choose from Visual Studio, which will initialize different environment variables.</p> <hr> <p><strong><em>Let's begin with this:</em></strong></p> <ol> <li><p>Download and install Perl: <a href="http://www.perl.org/get.html" rel="noreferrer">Download link</a></p></li> <li><p>Download and install Python: <a href="http://www.python.org/download" rel="noreferrer">Download link</a></p></li> <li><p>Download and install <strong><em>Windows SDK</em></strong> (probably not necessary, but recommended) I use Windows 8, so this is the version I used: <a href="http://msdn.microsoft.com/en-us/windows/desktop/hh852363.aspx" rel="noreferrer">Download link</a> ,Otherwise find the proper version for your Windows.</p></li> <li><p>Download and install <strong><em>DirectX SDK</em></strong> (probably necessary if you wanna compile with <em>OpenGL</em>) <a href="http://www.microsoft.com/en-us/download/details.aspx?id=6812" rel="noreferrer">Download link</a></p></li> <li><p>Download and extract <strong><em>jom</em></strong> to some folder (not needed for linux) (<em>jom</em> is a tool for compiling stuff with VS in parallel, there's a way to do this with <em>nmake</em>, but I'm not familiar with it) <a href="http://qt-project.org/wiki/jom" rel="noreferrer">Download link</a></p></li> <li><p>Download <strong><em>Qt Opensource</em></strong>, and extract it, say to <code>C:\Qt\Qt5.6</code>, so now the folder <code>qtbase</code> can be found in <code>C:\Qt\Qt5.6\qtbase</code> .</p></li> <li><p>Only for Windows: <strong>DO YOU REALLY WANT IT TOTALLY STATIC?</strong></p> <p>Usually, even if you choose the compilation to be static, the compiler itself will still not merge its libraries statically. If you want your compiled source to be fully static with respect to the compiler (Visual Studio), you have to do this tweak in the QMAKE files of Qt.</p> <p>Go to the file (starting from your Qt source directory), <strong>for versions higher than 2012, just use the right version everywhere (such as win32-msvc2015)</strong>:</p> <ul> <li><p>a. <strong>For VS2012:</strong> qtbase\mkspecs\win32-msvc2012\qmake.conf</p></li> <li><p>b. <strong>For VS2010:</strong> qtbase\mkspecs\win32-msvc2010\qmake.conf</p></li> <li><p>c. <strong>For Qt 5.5.0 and later</strong> (with any VS version): qtbase\mkspecs\common\msvc-desktop.conf</p></li> </ul> <p>and edit the following lines</p> <pre><code> QMAKE_CFLAGS_RELEASE = -O2 -MD QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi QMAKE_CFLAGS_DEBUG = -Zi -MDd </code></pre> <p>to</p> <pre><code> QMAKE_CFLAGS_RELEASE = -O2 -MT QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi QMAKE_CFLAGS_DEBUG = -Zi -MTd </code></pre></li> </ol> <p>Note: Qt 5.6+ have a configure parameter <code>-static-runtime</code> that will do this for you. You may not need to do this manually anymore for new versions of Qt.</p> <ol start="8"> <li><p>Start the terminal in linux, or in Windows, start the terminals of Visual Studio (which have the correct environment variables set, or alternatively use <a href="https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx?f=255&amp;MSPPError=-2147217396" rel="noreferrer">vcvarsall.bat</a>). To start the command prompt and let it do this automatically for you, go to Start, All Programs:</p> <p><em>For Windows versions prior to 8:</em> Find the Microsoft Visual Studio 201x folder, and launch the command prompt (either x86 for 32 bit or x64 for 64 bit).</p> <p><em>For Windows 8:</em> go to <em>Start</em>, type "cmd" and all versions available for command prompt will show up. Choose the Visual Studio version appropriate (x86 for 32 bit or x64 for 64 bit).</p></li> </ol> <p>Following is a screenshot of how it may look like. Always tend to select "Native" if it exists.</p> <p><a href="https://i.stack.imgur.com/EHD1X.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/EHD1X.jpg" alt="enter image description here"></a></p> <p>9.</p> <ul> <li><p><strong>For VS2012:</strong> Execute the following commands for VS2012</p> <pre><code> set QMAKESPEC=win32-msvc2012 set QTDIR=C:\Qt\Qt5.7\qtbase set PATH=C:\Qt\Qt5.7\qtbase\bin;%PATH% </code></pre></li> </ul> <p>Note: Setting <code>QMAKESPEC</code> environment variable is considered wrong for Qt versions 5.8+. Don't do it for the new versions.</p> <p>For dynamic linking (needs 8 GBs)</p> <pre><code>configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop </code></pre> <p>For dynamic linking with no examples (needs 2 GB)</p> <pre><code>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. </code></pre> <p>For static linking (needs 70 GBs, yes it's crazy, it's more reasonable not to make the examples and demos).</p> <pre><code>configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -static </code></pre> <p>For static linking with no examples (needs 4 GBs, makes more sense).</p> <pre><code>configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -static -nomake examples -nomake tests </code></pre> <p>Now this will take a minute or two, then use jom as follows (assuming it's extracted in C:\Qt\jom):</p> <pre><code>C:\Qt\jom\jom.exe -j 50 </code></pre> <p>50 represents the number of cores you want to use. I use 50 because I have 8 threads and using only 8 will not occupy all cores completely, so more is better, but don't get too greedy as it could make your system not responsive.</p> <ul> <li><p><strong>For VS2010:</strong> Execute the following commands for VS2010 </p> <pre><code>set QMAKESPEC=win32-msvc2010 set QTDIR=C:\Qt\Qt5.7\qtbase set PATH=C:\Qt\Qt5.7\qtbase\bin;%PATH% </code></pre></li> </ul> <p>Note: Setting <code>QMAKESPEC</code> environment variable is considered wrong for Qt versions 5.8+. Don't do it for the new versions. For dynamic linking (needs 8 GBs)</p> <pre><code>configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop </code></pre> <p>For dynamic linking with no examples (needs 2 GB)</p> <pre><code>configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -nomake examples -nomake tests </code></pre> <p>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 linking (needs 70 GBs, yes it's crazy, it's more reasonable not to make the examples and demos).</p> <pre><code>configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -static </code></pre> <p>For static linking with no examples (needs 4 GBs, makes more sense).</p> <pre><code>configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -static -nomake examples -nomake tests </code></pre> <p>Now this will take a minute or two, then use jom as follows (assuming it's extracted in C:\Qt\jom):</p> <pre><code>C:\Qt\jom\jom.exe -j 50 </code></pre> <p>50 represents the number of cores you want to use. I use 50 because I have 8 threads and using only 8 will not occupy all cores completely, so more is better, but don't get too greedy as it could make your system not responsive.</p> <ul> <li><strong>For linux:</strong> </li> </ul> <p>There's one small difference for Linux over Windows. It's recommended in linux to <em>install</em> after compiling. Honestly this is the only way it works for me without problems.</p> <p>Execute the following commands for Linux. Don't forget to replace the paths with the correct paths of your Qt source</p> <pre><code> export QMAKESPEC=linux-g++ export QTDIR=/home/username/Qt5.7/qtbase export PATH=/home/username/Qt5.7/qtbase/bin:$PATH </code></pre> <p>Note: Setting <code>QMAKESPEC</code> environment variable is considered wrong for Qt versions 5.8+. Don't do it for the new versions.</p> <p>Let's say you want to install the compiled source to the directory <code>/home/username/Qt5.7-install</code>. In this case, add the following to <em>any</em> of the configure commands below:</p> <pre><code>-prefix /home/username/Qt5.7-install </code></pre> <p><strong>Warning</strong>: DO NOT install to the same source directory. That's plain wrong!</p> <p>If <code>-prefix</code> is not set, the default path will be chosen, which is <code>/usr/local/</code> I guess. I don't like to install anything using root. I always prefer installing in my user folder, so that reversibility and upgrades are not a problem.</p> <p>The following are different possible <code>configure</code> commands depending on what you want to do.</p> <p>For dynamic linking (needs 8 GBs)</p> <pre><code>./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop </code></pre> <p>For dynamic linking with no examples (needs 2 GB)</p> <pre><code>./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -nomake examples -nomake tests </code></pre> <p>Now the last command depends on what you want to compile. Just type <code>./configure -help</code> and see what the available command-line parameters are.</p> <p>For static linking (needs 70 GBs, yes it's crazy, it's more reasonable not to make the examples and tests).</p> <pre><code>./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -static </code></pre> <p>For static linking with no examples (needs 4 GBs, makes more sense).</p> <pre><code>./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -static -nomake examples -nomake tests </code></pre> <p>After making is done, run make command</p> <pre><code>make -j 50 </code></pre> <p>50 represents the number of cores you want to use. I use 50 because I have 8 threads and using only 8 will not occupy all cores completely, so more is better, but don't get too greedy as it could make your system not responsive.</p> <ol start="10"> <li><p>Wait 2+ hours till the compilation is complete.</p></li> <li><p>Clean up! You can save a lot of space using this command for Windows: <code>C:\Qt\jom\jom.exe clean</code> And this command for linux: <code>make clean</code></p></li> </ol> <p>You can reduce the size of your compiled folder from 8 GB to 2.5 GB (for dynamic linking) and from 70 GB to 35 GB (for static linking).</p> <hr> <p>In order to use this compiled version in Qt Creator:</p> <ol> <li>Start Qt Creator</li> <li>Go to Tools, Options</li> <li>Select Build and Run from the list on the left.</li> <li>Go to "Qt Versions" tab</li> <li><p>Click on "Add" and select qmake from the folder where your bin in qtbase is, so from above:</p> <p>C:\Qt\Qt5.7\qtbase\bin\qmake.exe</p></li> </ol> <p>(or for Linux choose the path where you installed the compiled Qt source, which is equivalent to <code>/home/username/Qt5.7-install/qtbase/bin/qmake</code> in this tutorial)</p> <ol start="6"> <li>Click "Apply"</li> <li>Go to "Kits" tab</li> <li>Click "Add"</li> <li>Give it a name, choose the appropriate compiler (FOR VISUAL STUDIO EXPRESS DO NOT SELECT amd64 FOR 64-BIT , IT WON'T WORK, CHOOSE x86_amd64 INSTEAD)</li> <li>Click OK.</li> </ol> <p>Now just open a project and you'll find it asking you to choose the kit you added.</p> <p>Enjoy :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload