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 MSVC: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
[[Category:Developing with Qt::General]]<br />[[Category:HowTo]]
[[Category:Developing with Qt::General]]
[[Category:HowTo]]


[toc align_right=&quot;yes&amp;quot; depth=&quot;2&amp;quot;]
[toc align_right="yes" depth="2"]


= Building Qt Desktop for Windows with MSVC =
= Building Qt Desktop for Windows with MSVC =
Line 10: Line 11:


# Qt source code (I think you know where to find it :))
# Qt source code (I think you know where to find it :))
# On machines not having a previous Qt version already installed you need to install also Perl (e.g. &quot;ActivePerl&amp;quot;:http://www.activestate.com/activeperl/downloads ) prior to configure. Otherwise you may receive following error message at the end of configure:<br />&gt; Perl not found in environment - cannot run syncqt.
# On machines not having a previous Qt version already installed you need to install also Perl (e.g. "ActivePerl":http://www.activestate.com/activeperl/downloads ) prior to configure. Otherwise you may receive following error message at the end of configure:
# &quot;Microsoft Platform SDK&amp;quot;:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=35AEDA01-421D-4BA5-B44B-543DC8C33A20 (most recent at time of last wiki edit is Microsoft Windows 7.1 SDK.). The SDK includes the Microsoft Visual C++ compilers and debugging tools. You can in addition install &quot;Visual Studio Express&amp;quot;:http://www.microsoft.com/express/Downloads/ if you like the IDE (not required!).
> Perl not found in environment - cannot run syncqt.
# &quot;KB2485545&amp;quot;:https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=33355 or &quot;Service Pack 1&amp;quot;:http://www.microsoft.com/download/en/details.aspx?id=23691 are required for MSVC 2010 when building a 64bit library on intel x86 based CPUs. '''They fix a bug in the MSVC2010 compiler, and without it you will experience crashes when running 64bit binaries.'''
# "Microsoft Platform SDK":http://www.microsoft.com/downloads/en/details.aspx?FamilyID=35AEDA01-421D-4BA5-B44B-543DC8C33A20 (most recent at time of last wiki edit is Microsoft Windows 7.1 SDK.). The SDK includes the Microsoft Visual C++ compilers and debugging tools. You can in addition install "Visual Studio Express":http://www.microsoft.com/express/Downloads/ if you like the IDE (not required!).
# &quot;OpenSSL&amp;quot;:http://www.openssl.org/ libraries or source code (if you want to build it yourself)
# "KB2485545":https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=33355 or "Service Pack 1":http://www.microsoft.com/download/en/details.aspx?id=23691 are required for MSVC 2010 when building a 64bit library on intel x86 based CPUs. '''They fix a bug in the MSVC2010 compiler, and without it you will experience crashes when running 64bit binaries.'''
# "OpenSSL":http://www.openssl.org/ libraries or source code (if you want to build it yourself)


For Shared (if you want Phonon support) also required
For Shared (if you want Phonon support) also required


# &quot;Microsoft DirectX SDK&amp;quot;:http://go.microsoft.com/fwlink/?LinkID=71193&amp;amp;clcid=0x409
# "Microsoft DirectX SDK":http://go.microsoft.com/fwlink/?LinkID=71193&amp;amp;clcid=0x409


Ok, all done but… If you decided to build OpenSSL yourself (really, I recommend you) it is also required
Ok, all done but… If you decided to build OpenSSL yourself (really, I recommend you) it is also required


# &quot;ActivePerl&amp;quot;:http://www.activestate.com/activeperl/downloads (community edition is free)
# "ActivePerl":http://www.activestate.com/activeperl/downloads (community edition is free)
# &quot;The Netwide Assembler&amp;quot;:http://www.nasm.us
# "The Netwide Assembler":http://www.nasm.us


== Installation ==
== Installation ==
Line 28: Line 30:
At first I recommend you to install all packages into one directory (for example _C:):
At first I recommend you to install all packages into one directory (for example _C:):


* ''C:'' (for Visual C+'')<br />* ''C:7.1 SDK'' (for platform SDK)<br />* ''C:'' (for OpenSSL library or unpack source code anywhere for build)<br />* …
* ''C:'' (for Visual C+'')
<br />p. It is not required to install examples, demos, docs, libraries not for target architecture e.g. ;)
* ''C:7.1 SDK'' (for platform SDK)
<br />h2. Environment setup
* ''C:'' (for OpenSSL library or unpack source code anywhere for build)
<br />p. It looks good to have a script to set up the environment instead of setting it all using system PATH variable:
* …
<br /><code>&amp;#64;ECHO OFF
<br />set DEV=C:set QTDIR=&amp;#37;DEV&amp;amp;#37;set PATH=&amp;#37;SystemRoot&amp;amp;#37;;&amp;#37;SystemRoot&amp;amp;#37;32;&amp;#37;QTDIR&amp;amp;#37;
<br />echo Setting OpenSSL Env.<br />set OPENSSL=&amp;#37;DEV&amp;amp;#37;set PATH=&amp;#37;OPENSSL&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;<br />set LIB=&amp;#37;OPENSSL&amp;amp;#37;set INCLUDE=&amp;#37;OPENSSL&amp;amp;#37;
<br />echo Setting NASM Env.<br />set PATH=&amp;#37;DEV&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;
<br />echo Setting DirectX Env.<br />set LIB=&amp;#37;DEV&amp;amp;#37;SDK\Lib\x86;&amp;#37;LIB&amp;amp;#37;<br />set INCLUDE=&amp;#37;DEV&amp;amp;#37;SDK\Include;&amp;#37;INCLUDE&amp;amp;#37;
<br />echo Setting Windows SDK Env.<br />set WindowsSdkDir=&amp;#37;DEV&amp;amp;#37;7.1 SDK<br />set PATH=&amp;#37;WindowsSdkDir&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;<br />set LIB=&amp;#37;WindowsSdkDir&amp;amp;#37;;&amp;#37;LIB&amp;amp;#37;<br />set INCLUDE=&amp;#37;WindowsSdkDir&amp;amp;#37;;&amp;#37;INCLUDE&amp;amp;#37;<br />set TARGET_CPU=x86
<br />echo Setting MSVC2010 Env.<br />set VSINSTALLDIR=&amp;#37;DEV&amp;amp;#37;set VCINSTALLDIR=&amp;#37;DEV&amp;amp;#37;set DevEnvDir=&amp;#37;VSINSTALLDIR&amp;amp;#37;7\IDE<br />set PATH=&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;VSINSTALLDIR&amp;amp;#37;7\Tools;&amp;#37;VSINSTALLDIR&amp;amp;#37;7\IDE;&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;<br />set INCLUDE=&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;INCLUDE&amp;amp;#37;<br />set LIB=&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;LIB&amp;amp;#37;<br />set LIBPATH=&amp;#37;VCINSTALLDIR&amp;amp;#37;
<br />echo Setting Framework Env.<br />set FrameworkVersion=v4.0.30319<br />set Framework35Version=v3.5<br />set FrameworkDir=&amp;#37;SystemRoot&amp;amp;#37;.NET\Framework<br />set LIBPATH=&amp;#37;FrameworkDir&amp;amp;#37;amp;#37;FrameworkVersion&amp;amp;#37;;&amp;#37;FrameworkDir&amp;amp;#37;amp;#37;Framework35Version&amp;amp;#37;;&amp;#37;LIBPATH&amp;amp;#37;<br />set PATH=&amp;#37;LIBPATH&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;
<br />echo Env. ready.
<br />title Qt Framework 4.7.1 Development Kit.
<br />cd &amp;#37;DEV&amp;amp;#37;<br /></code>
<br />p. This file is '''.bat (or'''.cmd) script. Just modify and save it for your environment. I set it up from tool’s (MSVC, SDKs) prompts.
<br />p. You can add it to start menu or make a label (change script address at label preferences to &quot;cmd /k ''path/to/setqtenv.cmd''&quot;).
<br />h2. What we have
<br />[[Image:http://ompldr.org/vNmxzeg/c_development.PNG|C:\Development]]
<br />p. At my computer I have installed MSVC''+ 2010 Express Edition to ''C:'', Windows 7.1 SDK ''C:7.1 SDK'', DirectX SDK ''C:SDK'', Perl ''C:'' (impossible to change), NASM unpacked to ''C:'', Qt Desktop (4.7.1) source code (from ''qt-everywhere-opensource-src-4.7.1.tar.gz'') unpacked to ''C:'' and OpenSSL source code unpacked to ''C:–1.0.0c''


== &quot;Static&amp;quot; tips ==
p. It is not required to install examples, demos, docs, libraries not for target architecture e.g. ;)


Before you start to build a static Qt Desktop library, you must know that for now you will have a dependence with MSVC Redistributable. To escape this you must replace -MD (d) build flag with <s>MT (d) (''I will not recommend you use it, because it can cause runtime errors, etc.'' ''For example with this configuration I cannot start QtDesigner app.'' ''The reason is unknown.)''
h2. Environment setup
<br />p. It's available as both Static and Shared builds.
 
<br />h2. Building OpenSSL
p. It looks good to have a script to set up the environment instead of setting it all using system PATH variable:
<br />p. At first, open your new Qt prompt, ''cd'' to your OpennSSL source directory and setup (if not set) Perl bin directory path (and check it?):
 
<br /><code>&gt; cd openssl</s>*<br />&gt; set PATH=C:;&amp;#37;PATH&amp;amp;#37;<br />&gt; echo &amp;#37;PATH&amp;amp;#37;<br /></code>
<code>&amp;#64;ECHO OFF
 
set DEV=C:set QTDIR=&amp;#37;DEV&amp;amp;#37;set PATH=&amp;#37;SystemRoot&amp;amp;#37;;&amp;#37;SystemRoot&amp;amp;#37;32;&amp;#37;QTDIR&amp;amp;#37;
 
echo Setting OpenSSL Env.
set OPENSSL=&amp;#37;DEV&amp;amp;#37;set PATH=&amp;#37;OPENSSL&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;
set LIB=&amp;#37;OPENSSL&amp;amp;#37;set INCLUDE=&amp;#37;OPENSSL&amp;amp;#37;
 
echo Setting NASM Env.
set PATH=&amp;#37;DEV&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;
 
echo Setting DirectX Env.
set LIB=&amp;#37;DEV&amp;amp;#37;SDK\Lib\x86;&amp;#37;LIB&amp;amp;#37;
set INCLUDE=&amp;#37;DEV&amp;amp;#37;SDK\Include;&amp;#37;INCLUDE&amp;amp;#37;
 
echo Setting Windows SDK Env.
set WindowsSdkDir=&amp;#37;DEV&amp;amp;#37;7.1 SDK
set PATH=&amp;#37;WindowsSdkDir&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;
set LIB=&amp;#37;WindowsSdkDir&amp;amp;#37;;&amp;#37;LIB&amp;amp;#37;
set INCLUDE=&amp;#37;WindowsSdkDir&amp;amp;#37;;&amp;#37;INCLUDE&amp;amp;#37;
set TARGET_CPU=x86
 
echo Setting MSVC2010 Env.
set VSINSTALLDIR=&amp;#37;DEV&amp;amp;#37;set VCINSTALLDIR=&amp;#37;DEV&amp;amp;#37;set DevEnvDir=&amp;#37;VSINSTALLDIR&amp;amp;#37;7\IDE
set PATH=&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;VSINSTALLDIR&amp;amp;#37;7\Tools;&amp;#37;VSINSTALLDIR&amp;amp;#37;7\IDE;&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;
set INCLUDE=&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;INCLUDE&amp;amp;#37;
set LIB=&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;LIB&amp;amp;#37;
set LIBPATH=&amp;#37;VCINSTALLDIR&amp;amp;#37;
 
echo Setting Framework Env.
set FrameworkVersion=v4.0.30319
set Framework35Version=v3.5
set FrameworkDir=&amp;#37;SystemRoot&amp;amp;#37;.NET\Framework
set LIBPATH=&amp;#37;FrameworkDir&amp;amp;#37;amp;#37;FrameworkVersion&amp;amp;#37;;&amp;#37;FrameworkDir&amp;amp;#37;amp;#37;Framework35Version&amp;amp;#37;;&amp;#37;LIBPATH&amp;amp;#37;
set PATH=&amp;#37;LIBPATH&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;
 
echo Env. ready.
 
title Qt Framework 4.7.1 Development Kit.
 
cd &amp;#37;DEV&amp;amp;#37;
</code>
 
p. This file is '''.bat (or'''.cmd) script. Just modify and save it for your environment. I set it up from tool’s (MSVC, SDKs) prompts.
 
p. You can add it to start menu or make a label (change script address at label preferences to "cmd /k ''path/to/setqtenv.cmd''").
 
h2. What we have
 
[[Image:http://ompldr.org/vNmxzeg/c_development.PNG|C:\Development]]
 
p. At my computer I have installed MSVC''+ 2010 Express Edition to ''C:'', Windows 7.1 SDK ''C:7.1 SDK'', DirectX SDK ''C:SDK'', Perl ''C:'' (impossible to change), NASM unpacked to ''C:'', Qt Desktop (4.7.1) source code (from ''qt-everywhere-opensource-src-4.7.1.tar.gz'') unpacked to ''C:'' and OpenSSL source code unpacked to ''C:–1.0.0c''
 
== "Static" tips ==
 
Before you start to build a static Qt Desktop library, you must know that for now you will have a dependence with MSVC Redistributable. To escape this you must replace -MD (d) build flag with -MT (d) (''I will not recommend you use it, because it can cause runtime errors, etc.'' ''For example with this configuration I cannot start QtDesigner app.'' ''The reason is unknown.)''
 
p. It's available as both Static and Shared builds.
 
h2. Building OpenSSL
 
p. At first, open your new Qt prompt, ''cd'' to your OpennSSL source directory and setup (if not set) Perl bin directory path (and check it?):
 
<code>> cd openssl-*
> set PATH=C:;&amp;#37;PATH&amp;amp;#37;
> echo &amp;#37;PATH&amp;amp;#37;
</code>


Something like this:
Something like this:
Line 67: Line 119:
If you have NASM:
If you have NASM:


<code>&gt; perl Configure VC-WIN32 —prefix=C:&gt; ms\do&amp;amp;#95;nasm</code>
<code>> perl Configure VC-WIN32 —prefix=C:> ms\do&amp;amp;#95;nasm</code>


And if not:
And if not:


<code>&gt; perl Configure VC-WIN32 no-asm —prefix=C:&gt; ms\do&amp;amp;#95;ms</code>
<code>> perl Configure VC-WIN32 no-asm —prefix=C:> ms\do&amp;amp;#95;ms</code>


Here we set up compiler and destination directory.
Here we set up compiler and destination directory.
Line 77: Line 129:
Now open ''ms\ntdll.mak'' (for Static &amp;mdash; ''ms\nt.mak'') file and replace at '''LFLAGS''' ''/debug'' with ''/release''.
Now open ''ms\ntdll.mak'' (for Static &amp;mdash; ''ms\nt.mak'') file and replace at '''LFLAGS''' ''/debug'' with ''/release''.


For Static build flag -MT is applied by default (look at &quot;''Static''&quot; ''tips''). For shared -MD is used (change '''CFLAG'''’s at ''ms\ntdll.mak'' from /MD to /MT if required for you).
For Static build flag -MT is applied by default (look at "''Static''" ''tips''). For shared -MD is used (change '''CFLAG'''’s at ''ms\ntdll.mak'' from /MD to /MT if required for you).


Ok, building, testing and &quot;installing&amp;quot;:
Ok, building, testing and "installing":


For Shared:
For Shared:


<code>&gt; nmake -f ms\ntdll.mak<br />&gt; nmake -f ms\ntdll.mak test<br />&gt; nmake -f ms\ntdll.mak install</code>
<code>> nmake -f ms\ntdll.mak
> nmake -f ms\ntdll.mak test
> nmake -f ms\ntdll.mak install</code>


And for Static:
And for Static:


<code>&gt; nmake -f ms\nt.mak<br />&gt; nmake -f ms\nt.mak test<br />&gt; nmake -f ms\nt.mak install</code>
<code>> nmake -f ms\nt.mak
> nmake -f ms\nt.mak test
> nmake -f ms\nt.mak install</code>


Ready. Now you can remove your OpenSSL source code (''C:–1.0.0c'' here, on screenshot) directory and Perl installation. They are no longer required.
Ready. Now you can remove your OpenSSL source code (''C:–1.0.0c'' here, on screenshot) directory and Perl installation. They are no longer required.
Line 98: Line 154:
# Configure
# Configure


<blockquote>Note: MSVC supports build with multiple processes. Really. You can add -MP[processMax] flag. Details &quot;here&amp;quot;:http://msdn.microsoft.com/en-us/library/bb385193.aspx.
<blockquote>Note: MSVC supports build with multiple processes. Really. You can add -MP[processMax] flag. Details "here":http://msdn.microsoft.com/en-us/library/bb385193.aspx.
</blockquote>
</blockquote>
For first step (are you really sure with &quot;Static&amp;quot; tips?) we are going to ''&amp;#37;QTDIR&amp;amp;#37;32-msvc2010'' (I know that you know that real path is ''C:32-msvc2010'' and if you have different version of MSVC it will be different spec directory ;)). Here we are interested in the ''qmake.conf'' configuration file.
For first step (are you really sure with "Static" tips?) we are going to ''&amp;#37;QTDIR&amp;amp;#37;32-msvc2010'' (I know that you know that real path is ''C:32-msvc2010'' and if you have different version of MSVC it will be different spec directory ;)). Here we are interested in the ''qmake.conf'' configuration file.


Edit '''QMAKE_CFLAGS_RELEASE''', '''QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO''' &amp; '''QMAKE_CFLAGS_DEBUG''' variables. For example:
Edit '''QMAKE_CFLAGS_RELEASE''', '''QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO''' &amp; '''QMAKE_CFLAGS_DEBUG''' variables. For example:


<code>QMAKE_CFLAGS_RELEASE = -O2 -MD -MP2<br />QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi -MP2<br />QMAKE_CFLAGS_DEBUG = -Zi -MDd -MP2<br /></code>
<code>QMAKE_CFLAGS_RELEASE = -O2 -MD -MP2
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi -MP2
QMAKE_CFLAGS_DEBUG = -Zi -MDd -MP2
</code>


Next &amp;mdash; configuring. My configuration (shared) is:
Next &amp;mdash; configuring. My configuration (shared) is:


<code>&gt; configure -release -opensource -shared -ltcg -no-fast -exceptions -accessibility -stl -qt-sql-sqlite -no-qt3support -no-openvg -platform win32-msvc2010 -graphicssystem raster -qt-zlib -qt-gif -qt-libpng -qt-libmng -qt-libtiff -qt-libjpeg -no-dsp -no-vcproj -incredibuild-xge -plugin-manifests -qmake -process -rtti -mmx –3dnow -sse -sse2 -openssl -no-dbus -phonon -phonon-backend -multimedia -audio-backend -webkit -script -scripttools -declarative -arch windows -qt-style-windows -qt-style-windowsxp -qt-style-windowsvista -no-style-plastique -no-style-cleanlooks -no-style-motif -no-style-cde -no-style-windowsce -no-style-windowsmobile -no-style-s60 -native-gestures<br /></code>
<code>> configure -release -opensource -shared -ltcg -no-fast -exceptions -accessibility -stl -qt-sql-sqlite -no-qt3support -no-openvg -platform win32-msvc2010 -graphicssystem raster -qt-zlib -qt-gif -qt-libpng -qt-libmng -qt-libtiff -qt-libjpeg -no-dsp -no-vcproj -incredibuild-xge -plugin-manifests -qmake -process -rtti -mmx –3dnow -sse -sse2 -openssl -no-dbus -phonon -phonon-backend -multimedia -audio-backend -webkit -script -scripttools -declarative -arch windows -qt-style-windows -qt-style-windowsxp -qt-style-windowsvista -no-style-plastique -no-style-cleanlooks -no-style-motif -no-style-cde -no-style-windowsce -no-style-windowsmobile -no-style-s60 -native-gestures
</code>


As you see, I do not want to build Qt3 support module, some styles, using image libs from Qt source, some additional instructions sets are enabled and some another stuff.
As you see, I do not want to build Qt3 support module, some styles, using image libs from Qt source, some additional instructions sets are enabled and some another stuff.
Line 122: Line 182:
Copy (or move) OpenSSL libraries (*.dll) from ''&amp;#37;QTDIR&amp;amp;#37;'' directory to Qt bin directory and add ''&amp;#37;QTDIR&amp;amp;#37;'' to system ''&amp;#37;PATH&amp;amp;#37;'' variable.
Copy (or move) OpenSSL libraries (*.dll) from ''&amp;#37;QTDIR&amp;amp;#37;'' directory to Qt bin directory and add ''&amp;#37;QTDIR&amp;amp;#37;'' to system ''&amp;#37;PATH&amp;amp;#37;'' variable.


<code>&gt; move OpenSSL\bin.dll Qt\bincode&gt;
<code>> move OpenSSL\bin.dll Qt\bincode>


== Reduce used HDD space ==
== Reduce used HDD space ==
Line 129: Line 189:


Just at ''&amp;#37;QTDIR&amp;amp;#37;'' run ''nmake clean'' to delete all tmp objects, etc. Then rebuild translations (go to ''&amp;#37;QTDIR&amp;amp;#37;'' and run ''nmake''). And remove libraries ('''.dll) from ''&amp;#37;QTDIR&amp;amp;#37;''.
Just at ''&amp;#37;QTDIR&amp;amp;#37;'' run ''nmake clean'' to delete all tmp objects, etc. Then rebuild translations (go to ''&amp;#37;QTDIR&amp;amp;#37;'' and run ''nmake''). And remove libraries ('''.dll) from ''&amp;#37;QTDIR&amp;amp;#37;''.
<br /></code>&gt; cd Qt<br />&gt; nmake clean<br />&gt; cd translations<br />&gt; nmake<br />&gt; cd ..&gt; del'''.dll<br /><code>
 
</code>> cd Qt
> nmake clean
> cd translations
> nmake
> cd ..> del'''.dll
<code>

Revision as of 08:44, 25 February 2015


[toc align_right="yes" depth="2"]

Building Qt Desktop for Windows with MSVC

Required SDKs and tools

Here are the tools required to build a Qt Shared or a Qt Static library. First, please, download and install :

  1. Qt source code (I think you know where to find it :))
  2. On machines not having a previous Qt version already installed you need to install also Perl (e.g. "ActivePerl":http://www.activestate.com/activeperl/downloads ) prior to configure. Otherwise you may receive following error message at the end of configure:

> Perl not found in environment - cannot run syncqt.

  1. "Microsoft Platform SDK":http://www.microsoft.com/downloads/en/details.aspx?FamilyID=35AEDA01-421D-4BA5-B44B-543DC8C33A20 (most recent at time of last wiki edit is Microsoft Windows 7.1 SDK.). The SDK includes the Microsoft Visual C++ compilers and debugging tools. You can in addition install "Visual Studio Express":http://www.microsoft.com/express/Downloads/ if you like the IDE (not required!).
  2. "KB2485545":https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=33355 or "Service Pack 1":http://www.microsoft.com/download/en/details.aspx?id=23691 are required for MSVC 2010 when building a 64bit library on intel x86 based CPUs. They fix a bug in the MSVC2010 compiler, and without it you will experience crashes when running 64bit binaries.
  3. "OpenSSL":http://www.openssl.org/ libraries or source code (if you want to build it yourself)

For Shared (if you want Phonon support) also required

  1. "Microsoft DirectX SDK":http://go.microsoft.com/fwlink/?LinkID=71193&amp;clcid=0x409

Ok, all done but… If you decided to build OpenSSL yourself (really, I recommend you) it is also required

  1. "ActivePerl":http://www.activestate.com/activeperl/downloads (community edition is free)
  2. "The Netwide Assembler":http://www.nasm.us

Installation

At first I recommend you to install all packages into one directory (for example _C:):

  • C: (for Visual C+)
  • C:7.1 SDK (for platform SDK)
  • C: (for OpenSSL library or unpack source code anywhere for build)

p. It is not required to install examples, demos, docs, libraries not for target architecture e.g. ;)

h2. Environment setup

p. It looks good to have a script to set up the environment instead of setting it all using system PATH variable:

&amp;#64;ECHO OFF

set DEV=C:set QTDIR=&amp;#37;DEV&amp;amp;#37;set PATH=&amp;#37;SystemRoot&amp;amp;#37;;&amp;#37;SystemRoot&amp;amp;#37;32;&amp;#37;QTDIR&amp;amp;#37;

echo Setting OpenSSL Env.
set OPENSSL=&amp;#37;DEV&amp;amp;#37;set PATH=&amp;#37;OPENSSL&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;
set LIB=&amp;#37;OPENSSL&amp;amp;#37;set INCLUDE=&amp;#37;OPENSSL&amp;amp;#37;

echo Setting NASM Env.
set PATH=&amp;#37;DEV&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;

echo Setting DirectX Env.
set LIB=&amp;#37;DEV&amp;amp;#37;SDK\Lib\x86;&amp;#37;LIB&amp;amp;#37;
set INCLUDE=&amp;#37;DEV&amp;amp;#37;SDK\Include;&amp;#37;INCLUDE&amp;amp;#37;

echo Setting Windows SDK Env.
set WindowsSdkDir=&amp;#37;DEV&amp;amp;#37;7.1 SDK
set PATH=&amp;#37;WindowsSdkDir&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;
set LIB=&amp;#37;WindowsSdkDir&amp;amp;#37;;&amp;#37;LIB&amp;amp;#37;
set INCLUDE=&amp;#37;WindowsSdkDir&amp;amp;#37;;&amp;#37;INCLUDE&amp;amp;#37;
set TARGET_CPU=x86

echo Setting MSVC2010 Env.
set VSINSTALLDIR=&amp;#37;DEV&amp;amp;#37;set VCINSTALLDIR=&amp;#37;DEV&amp;amp;#37;set DevEnvDir=&amp;#37;VSINSTALLDIR&amp;amp;#37;7\IDE
set PATH=&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;VSINSTALLDIR&amp;amp;#37;7\Tools;&amp;#37;VSINSTALLDIR&amp;amp;#37;7\IDE;&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;
set INCLUDE=&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;INCLUDE&amp;amp;#37;
set LIB=&amp;#37;VCINSTALLDIR&amp;amp;#37;;&amp;#37;LIB&amp;amp;#37;
set LIBPATH=&amp;#37;VCINSTALLDIR&amp;amp;#37;

echo Setting Framework Env.
set FrameworkVersion=v4.0.30319
set Framework35Version=v3.5
set FrameworkDir=&amp;#37;SystemRoot&amp;amp;#37;.NET\Framework
set LIBPATH=&amp;#37;FrameworkDir&amp;amp;#37;amp;#37;FrameworkVersion&amp;amp;#37;;&amp;#37;FrameworkDir&amp;amp;#37;amp;#37;Framework35Version&amp;amp;#37;;&amp;#37;LIBPATH&amp;amp;#37;
set PATH=&amp;#37;LIBPATH&amp;amp;#37;;&amp;#37;PATH&amp;amp;#37;

echo Env. ready.

title Qt Framework 4.7.1 Development Kit.

cd &amp;#37;DEV&amp;amp;#37;

p. This file is .bat (or.cmd) script. Just modify and save it for your environment. I set it up from tool’s (MSVC, SDKs) prompts.

p. You can add it to start menu or make a label (change script address at label preferences to "cmd /k path/to/setqtenv.cmd").

h2. What we have

C:\Development

p. At my computer I have installed MSVC+ 2010 Express Edition to C:, Windows 7.1 SDK C:7.1 SDK, DirectX SDK C:SDK, Perl C: (impossible to change), NASM unpacked to C:, Qt Desktop (4.7.1) source code (from qt-everywhere-opensource-src-4.7.1.tar.gz) unpacked to C: and OpenSSL source code unpacked to C:–1.0.0c

"Static" tips

Before you start to build a static Qt Desktop library, you must know that for now you will have a dependence with MSVC Redistributable. To escape this you must replace -MD (d) build flag with -MT (d) (I will not recommend you use it, because it can cause runtime errors, etc. For example with this configuration I cannot start QtDesigner app. The reason is unknown.)

p. It's available as both Static and Shared builds.

h2. Building OpenSSL

p. At first, open your new Qt prompt, cd to your OpennSSL source directory and setup (if not set) Perl bin directory path (and check it?):

> cd openssl-*
> set PATH=C:;&amp;#37;PATH&amp;amp;#37;
> echo &amp;#37;PATH&amp;amp;#37;

Something like this:

OpenSSL build setup

If all is ok, we can continue…

Configuring and preparing OpenSSL (copy-paste it, here is underscore symbols):

If you have NASM:

> perl Configure VC-WIN32 prefix=C:> ms\do&amp;amp;#95;nasm

And if not:

> perl Configure VC-WIN32 no-asm prefix=C:> ms\do&amp;amp;#95;ms

Here we set up compiler and destination directory.

Now open ms\ntdll.mak (for Static &mdash; ms\nt.mak) file and replace at LFLAGS /debug with /release.

For Static build flag -MT is applied by default (look at "Static" tips). For shared -MD is used (change CFLAG’s at ms\ntdll.mak from /MD to /MT if required for you).

Ok, building, testing and "installing":

For Shared:

> nmake -f ms\ntdll.mak
> nmake -f ms\ntdll.mak test
> nmake -f ms\ntdll.mak install

And for Static:

> nmake -f ms\nt.mak
> nmake -f ms\nt.mak test
> nmake -f ms\nt.mak install

Ready. Now you can remove your OpenSSL source code (C:–1.0.0c here, on screenshot) directory and Perl installation. They are no longer required.

Configuring Qt Desktop

There are 2 steps:

  1. Check/Change build flags
  2. Configure

Note: MSVC supports build with multiple processes. Really. You can add -MP[processMax] flag. Details "here":http://msdn.microsoft.com/en-us/library/bb385193.aspx.

For first step (are you really sure with "Static" tips?) we are going to &#37;QTDIR&amp;#37;32-msvc2010 (I know that you know that real path is C:32-msvc2010 and if you have different version of MSVC it will be different spec directory ;)). Here we are interested in the qmake.conf configuration file.

Edit QMAKE_CFLAGS_RELEASE, QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO & QMAKE_CFLAGS_DEBUG variables. For example:

QMAKE_CFLAGS_RELEASE = -O2 -MD -MP2
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi -MP2
QMAKE_CFLAGS_DEBUG = -Zi -MDd -MP2

Next &mdash; configuring. My configuration (shared) is:

> configure -release -opensource -shared -ltcg -no-fast -exceptions -accessibility -stl -qt-sql-sqlite -no-qt3support -no-openvg -platform win32-msvc2010 -graphicssystem raster -qt-zlib -qt-gif -qt-libpng -qt-libmng -qt-libtiff -qt-libjpeg -no-dsp -no-vcproj -incredibuild-xge -plugin-manifests -qmake -process -rtti -mmx 3dnow -sse -sse2 -openssl -no-dbus -phonon -phonon-backend -multimedia -audio-backend -webkit -script -scripttools -declarative -arch windows -qt-style-windows -qt-style-windowsxp -qt-style-windowsvista -no-style-plastique -no-style-cleanlooks -no-style-motif -no-style-cde -no-style-windowsce -no-style-windowsmobile -no-style-s60 -native-gestures

As you see, I do not want to build Qt3 support module, some styles, using image libs from Qt source, some additional instructions sets are enabled and some another stuff.

Configuring Qt Desktop

Ok, let’s configure… Accepting license… Please, wait… (building qmake now) :)

All the project’s files are read and now we able to build libs, tools, examples, etc. Just nmake it to build all. Also we are able to make only libs (nmake sub-src), tools (nmake sub-tools, but after libs)…

Recommendations

Copy (or move) OpenSSL libraries (*.dll) from &#37;QTDIR&amp;#37; directory to Qt bin directory and add &#37;QTDIR&amp;#37; to system &#37;PATH&amp;#37; variable.

> move OpenSSL\bin.dll Qt\bincode>

== Reduce used HDD space ==

'''Attention! This operations removes debugging information! (if you set release-and-debug)'''

Just at ''&amp;#37;QTDIR&amp;amp;#37;'' run ''nmake clean'' to delete all tmp objects, etc. Then rebuild translations (go to ''&amp;#37;QTDIR&amp;amp;#37;'' and run ''nmake''). And remove libraries ('''.dll) from ''&amp;#37;QTDIR&amp;amp;#37;''.

> cd Qt

> nmake clean > cd translations > nmake > cd ..> del.dll