{"id":399,"date":"2015-07-04T14:41:30","date_gmt":"2015-07-04T14:41:30","guid":{"rendered":"https:\/\/blog.afach.de\/?page_id=399"},"modified":"2016-12-17T22:09:44","modified_gmt":"2016-12-17T22:09:44","slug":"how-to-compile-qt-5-from-git-source-compiling-batch-file","status":"publish","type":"page","link":"https:\/\/blog.afach.de\/?page_id=399","title":{"rendered":"Qt 5 &#8211; How to compile Qt 5 from git source &#8211; Auto Compiling batch file"},"content":{"rendered":"<p>Did this article help you? Let me know in the comments.<\/p>\n<p><strong>To compile Qt 5 using\u00a0Visual Studio easily<\/strong><\/p>\n<p>Compiling Qt 5 can become annoying, as it&#8217;s nothing but a routine task that could be time wasting. Here I&#8217;ll introduce a batch script that compiles Qt 5 from its git repository for me and for all those interested. The following is the batch script, and after it you&#8217;ll find instructions on how to use it:<\/p>\n<pre>@echo off\r\nset \"qtver=%1\"\r\nset \"prefix=Qt\"\r\nset \"suffix=_src\"\r\nset \"buildSuffix=%2\"\r\nset \"folder=%prefix%%qtver%%suffix%\"\r\nif \"%buildSuffix%\" == \"\" set compilefolder=%prefix%%qtver%\r\nif NOT \"%buildSuffix%\" == \"\" set compilefolder=%prefix%%qtver%_%buildSuffix%\r\n\r\nif \"%qtver%\" == \"\" goto :leave\r\n\r\nCALL git clone https:\/\/code.qt.io\/qt\/qt5.git %folder%\r\nCALL cd %folder%\r\nCALL git checkout .\r\nCALL git checkout %qtver%\r\nif NOT %ERRORLEVEL% == 0 goto :errorcheckout\r\nCALL perl init-repository\r\nCALL cd ..\\\r\necho Download done... press enter to start compiling.\r\npause\r\n\r\nset PATH=%cd%\\%folder%\\bin;%PATH%\r\nset QTDIR=%cd%\\%folder%\\qtbase\r\nmkdir %compilefolder%\r\ncall cd %compilefolder%\r\nset QMAKESPEC=win32-msvc2013\r\nset CL=\/MP\r\nCALL ..\\%folder%\\configure -developer-build -confirm-license -debug-and-release -opensource -platform %QMAKESPEC% -opengl desktop -static -nomake examples -nomake tests -mp -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg\r\n\r\nCALL nmake\r\n::CALL nmake clean\r\n\r\n:leave\r\nif \"%qtver%\" == \"\" echo Please enter a version as the first parameter, and the build directory suffix as the second parameter\r\nexit \/b 1\r\n\r\n:errorcheckout\r\necho Checkout error... The version you chose does not exist exiting\r\nexit \/b 1<\/pre>\n<p><strong>Important:<\/strong> Starting from Qt 5.7.0, the options -c++11 doesn&#8217;t work anymore, so remove it from configure. This is because c++11 became a requirement at that release.<\/p>\n<p>Notice the following:<\/p>\n<p>1- Notice that :: before any line means it&#8217;s commented.<br \/>\n2- Notice also that this compiles a static version of Qt. You&#8217;re free to modify it!<br \/>\n3- I commented the command &#8220;nmake clean&#8221;, which you can enable. I commented it to ensure that compilation went fine before I do a clean up. A clean up is necessary, as it saves many GB of diskspace.<br \/>\n4- I don&#8217;t compile demos and example because they take huge diskspace with no benefit. Again, you&#8217;re free to modify this.<br \/>\n5- Don&#8217;t forget to change the following line with the correct version of your visual studio.<\/p>\n<pre>set QMAKESPEC=win32-msvc2013<\/pre>\n<p>Simply save the contents of this in a batch file, for example DownloadQt.bat, put it in a new, empty folder, and then execute it after following the following instructions.<\/p>\n<p>The execution command is:<\/p>\n<pre>DownloadQt.bat &lt;qt version&gt; &lt;compiled folder suffix&gt;<\/pre>\n<p>For example, if you run the following:<\/p>\n<pre>DownloadQt.bat 5.5.0 64_VS2013<\/pre>\n<p>This will download the source to Qt5_src, and then create a new folder called Qt5.5.0_64_VS2013, where the compiled source is put. I use the suffixed to add information about VS version and whether it&#8217;s 32 or 64 bit.<\/p>\n<h3>Requirements<\/h3>\n<p>1- <a href=\"https:\/\/git-scm.com\/download\/win\">Git<\/a><br \/>\n2- <a href=\"http:\/\/strawberryperl.com\/\">Perl<\/a> (I recommend strawberry Perl)<br \/>\n3- <a href=\"http:\/\/msdn.microsoft.com\/en-us\/windows\/desktop\/hh852363.aspx\">Windows SDK<\/a><br \/>\n4- <a href=\"https:\/\/www.visualstudio.com\/en-us\/products\/visual-studio-express-vs.aspx\">Visual Studio or C++ Express<\/a>\u00a0(this you can get for free from Microsoft, but I assume you know enough about this already since you&#8217;re here)<\/p>\n<p><strong>IMPORTANT<\/strong>: It&#8217;s very recommended that you add git and perl\u00a0to the %PATH% environment. The installers will ask you to do that, so accept it! They&#8217;re doing you a favor! Otherwise you&#8217;ll have to do it manually later.<\/p>\n<h3>32-bit or 64-bit?<\/h3>\n<p>Whether you&#8217;d like to have a 32-bit or 64-bit version of visual studio used depends on the environment variables that are defined.\u00a0The easiest way is to run the run command prompt for the version you want. For example, in Visual Studio 2013, if one goes to Start, then types in quick search &#8220;Visual&#8221;, you&#8217;ll find a folder called &#8220;Visual Studio Tools&#8221;. This folder will have both command prompts with the relevant environment variables. The following shows this folder:<\/p>\n<p><a href=\"https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/VisualStudioCMDShortcuts.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-400 size-full\" src=\"https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/VisualStudioCMDShortcuts.jpg\" alt=\"VisualStudioCMDShortcuts\" width=\"2179\" height=\"1034\" srcset=\"https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/VisualStudioCMDShortcuts.jpg 2179w, https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/VisualStudioCMDShortcuts-300x142.jpg 300w, https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/VisualStudioCMDShortcuts-1024x486.jpg 1024w\" sizes=\"auto, (max-width: 2179px) 100vw, 2179px\" \/><\/a><\/p>\n<p>It&#8217;s important that you compile Qt from such a command prompt.<\/p>\n<p>PS: As far as I remember, Visual Studio 2010 Express and earlier doesn&#8217;t provide a 64-bit version (unless paid for).<\/p>\n<h3>Caveats about perl version<\/h3>\n<p>Perl is necessary because the Qt 5 repository is a git repository with <a href=\"http:\/\/git-scm.com\/docs\/git-submodule\">submodules<\/a>. Manually downloading the submodules could be annoying, so the Qt people created a perl\u00a0script to do the job for you.\u00a0Git for Windows comes with a version of perl. This version could be old and could cause problems. If you execute the script and it fails in downloading Qt source\u00a0from the repository, you have to make sure of a few things:<\/p>\n<p>1) Make sure that git is in %PATH% environement variable. When you&#8217;re in the VS201x command prompt, just execute &#8220;git&#8221;. If that creates\u00a0a problem in the form of &#8220;not found&#8221;, then you should add git&#8217;s bin folder to path using<\/p>\n<pre><code>set PATH=C:\\Program Files (x86)\\git\\bin;%PATH%<\/code><\/pre>\n<p>Remember to replace the path with\u00a0your git path.<\/p>\n<p>2) After ensuring git is in %PATH%, try running the batch script. If you get an error, this most likely means that the perl version is an old one that is taken from the git directory. To fix this, go to git&#8217;s bin folder, supposedly:<\/p>\n<pre><code>C:\\Program Files (x86)\\git\\bin<\/code><\/pre>\n<p>and change the file name &#8220;perl.exe&#8221; to &#8220;perl1.exe&#8221;. This works fine. If you&#8217;re unconfortable with this, you can restore it after compiling your version of Qt 5.<\/p>\n<p>3) Ensure that perl is also in path. Just run &#8220;perl&#8221; in your VS201x command prompt. Again, if it creates a problem, then you have to add &#8220;C:\\Strawberry\\perl\\bin&#8221; to your %PATH%.<\/p>\n<h3>Modifying Qt before compiling?<\/h3>\n<p>The script is made to download and compile. To give you a chance to modify the downloaded source for any reason, the script notifies you and pauses after downloading the source and expects a key pressed from your side.<\/p>\n<p>For example, you may wanna edit the following file\u00a0in the downloaded source<\/p>\n<pre><code>qtbase\/mkspecs\/common\/msvc-desktop.conf<\/code><\/pre>\n<p>By changing the following lines<\/p>\n<pre>QMAKE_CFLAGS_RELEASE = -O2 -MD\r\nQMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi\r\nQMAKE_CFLAGS_DEBUG = -Zi -MDd<\/pre>\n<p>To the following:<\/p>\n<pre>QMAKE_CFLAGS_RELEASE = -O2 -MT\r\nQMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi\r\nQMAKE_CFLAGS_DEBUG = -Zi -MTd<\/pre>\n<p>This will make the compliled Qt version\u00a0<strong>really static against the compiler standard library<\/strong>. Otherwise you&#8217;ll require the runtime.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did this article help you? Let me know in the comments. To compile Qt 5 using\u00a0Visual Studio easily Compiling Qt 5 can become annoying, as it&#8217;s nothing but a routine task that could be time wasting. Here I&#8217;ll introduce a batch script that compiles Qt 5 from its git repository for me and for all &hellip; <a href=\"https:\/\/blog.afach.de\/?page_id=399\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Qt 5 &#8211; How to compile Qt 5 from git source &#8211; Auto Compiling batch file<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":397,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-399","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/pages\/399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.afach.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=399"}],"version-history":[{"count":24,"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/pages\/399\/revisions"}],"predecessor-version":[{"id":653,"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/pages\/399\/revisions\/653"}],"up":[{"embeddable":true,"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/pages\/397"}],"wp:attachment":[{"href":"https:\/\/blog.afach.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}