2007年9月27日星期四

building qt4 with vc2005

Introduction

In this article I'll try to give step by step explanation of how to build QT4 using latest Microsoft Visual C++ 2005 (8.0) compiler. These instructions are based on article Compiling Qt4 on Windows from PsiWiki.

Prerequisites

  1. You need to have Microsoft Visual C++ 2005 installed. You can use VC++ compiler from every edition of Visual Studio, even from Express Edition (free).

  2. Download Qt/Windows Open Source Edition.

  3. Download unofficial patch for QT4 from qt-win project.

/!\ IMPORTANT Select appropriate version of qt-win patch for version of QT you've downloaded.

Examples:

  • QT 4.1.0 -> patch for QT 4.1.0

  • QT 4.1.1 -> patch for QT 4.1.1

  • etc.

Mixing those versions can cause undefined behaviour and compilation likely will fail. I did so, and had to fight with many problems. Here you can find my story about it the Qt Centre.

Notes about my environment configuration

  1. I unpacked QT 4.1.1 sources into the following directory:
    D:\lib\qt\4.1.1 
    So, I set QTDIR environment variable as follows:
    QTDIR=D:\lib\qt\4.1.1

    During further explantion I'll use %QTDIR% refering to the location above.

  2. I use Visual C++ 2005 Professional Edition installed in the following location:
    C:\Program Files\Microsoft Visual Studio 8 
  3. Visual C++ configuration script can be found here:
    C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat 

First: Apply qt-win patch

  1. You should have downloaded qt-win patch. If you have QT 4.1.1 you need this fileacs4qt411p1.zip

  2. Unpack the patch from ZIP to your %QTDIR%.

  3. Open Command Line window and move to the %QTDIR%.

  4. Run installpatch41.bat script

    D:\lib\qt\4.1.1>installpatch41.bat
    You will see many messages like:
    patching file qconfigure.bat
    patching file examples/threads/waitconditions/waitconditions.pro
    patching file misc/bcc32pch/Makefile.win32-borland
    ...
    Check the output for possible errors. If there are no errors, patch is applied correctly.

Second: Compile QT4 using VC++ 2005

After qt-win patch is applied you can start building QT4 with Visual C++ 2005 compiler.

  1. Run vsvars32.bat script to configure environment for VC++ 2005 compiler

    D:\lib\qt\4.1.1>"C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
    Setting environment for using Microsoft Visual Studio 2005 x86 tools.
    Note the quotation marks around the path to script. They're required because path includes spaces.
  2. Run qconfigure.bat script specifying VC++ 2005 compiler Please, write the name of the script correctly. It's qconfigure.bat but not configure.exe which also exists in the %QTDIR%.

    D:\lib\qt\4.1.1>qconfigure.bat msvc2005

    This is the Qt/Windows Open Source Edition.

    You are licensed to use this software under the terms of
    the GNU General Public License.

    Type '?' to view the GNU General Public License.
    Type 'y' to accept this license offer.
    Type 'n' to decline this license offer.

    Do you accept the terms of the license?

    Now, accept the license according to instructions above giving y and confirming with enter key. After this step, nmake will run automatically and VC++ 2005 will start building QT4. This process can take a few minutes, depending on speed of your hardware.

  3. After compilation is finished without any errors, you should have following binaries ready to use or run:
    • QT4 Libraries
    • QT4 Tools like designer, assistance and linguist

    • QT4 Demo applications
    • QT4 Examples

    Here is sample screenshot presenting QT Tools compiled with VC++ 2005

Third: Environment Configurtion

  1. Open My Computer -> Properties -> Advanced -> Environment Variables

  2. Add new variable QTDIR as follows

    QTDIR=D:\lib\qt\4.1.1 
  3. To PATH variable add following path:

    %QTDIR%\bin 
  4. Configure Visual C++ 2005 settings. Open Tools -> Options dialog box.

    Add following directories under QTDIR to Include files:

    Add QTDIR\lib directory to Library files:

Notes about Visual C++ 2005 Express Edition

Elmar de Koning wrote to me about his experience in building QT4 with Visual C++ 2005 EE. I'd like to thank Elmar for this note. Here is the essence of Elmar's e-mail:

  • Well I managed to do just that, although several additional steps were needed. In short, vs2005 express comes with no platform SDK, but the "Microsoft Windows Core SDK" part is needed to build qt4. This document describes in short how to get it what to do with it after you downloaded it. I suggest using the "Windows® Server 2003 R2 Platform SDK Web Install" option from here as that allows you to just download the core sdk instead of the whole 400MB package.

/!\ Note: The first link in the above paragraph appears to be dead. You can access that same page using the internet wayback timemachine here. TS

I (TimSutton) would like to make some additional notes here since I built Qt4.3.1 with Visual C++ Express and ran into many hiccups. Firstly dont forget that you always need to run vsvars32.bat in any shell you open otherwise your environment wont be set up properly. Next you really need to take care that your %LIB%,%INCLUDE% and %PATH% environment variables are set properly in

Here is what my %LIB% dir looked like after installing the SDK and setting everything up:

C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib;
C:\Program Files\Microsoft Visual Studio 8\VC\LIB;
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;

Here is my %PATH%;

C:\Program Files\CMake 2.4\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;
"c:\Program Files\Microsoft Visual Studio 8\Common7\Tools";
c:\Qt\4.3.1\bin;C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin\.;
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin\WinNT\;
C:\Program Files\svn\bin;C:\Program Files\Microsoft Visual Studio 8\VC\bin;
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE

The End

If you have any problems or questions, please contact me on mateusz@loskot.net . Also, I'd like to hear if someone managed to build QT4 using Visual C++ Express Edition without problems. So, please send me a note about that or put some info on this wikipage.

I'd like to thank authors of PsiWiki for their article about building QT4 with Visual C++.

Next Step

I'm going to publish step by step HOWTO about building Quantum GIS using Visual C++ 2005 compiler. I'll provide you with complete and working solution and project files as well.

References

Qt4 on Free IDE Visual Studio Express 2005 C++ with Qt code completion

Building QT 4 with Visual C++ 2005 (2007-09-24 20:37:25由TimSutton编辑)

没有评论: