The Linux Page

Compile Qt 4.7.x with Visual Studio 10 (VC++ 2010)

Try to recompile Qt with Pavel's instructrions...

I did not encounter much problems, although the examples failed. It looks like jom would be the problem as some people reported not having problems following the same steps, but using nmake instead of jom.

The instructions go like this: [Update: the links below all stopped working.]

  1. Visual C++ 2010 contains all necessary SDKs for Qt compilation. However if you plan to use Qt with Phonon you need to install additional software from Qt for Windows Requirements list.
     
  2. Download and extract Qt 4.7.4 Sources. (Or Qt 4.7.3, Qt 4.7.1)
     
  3. Copy contents of the folder qt-everywhere-opensource-src-4.7.4 to the directory where you intend to install Qt. In our case this is C:\Qt\4.7.4.
     
  4. Set up environmental variables

      QTDIR=C:\Qt\4.7.4
      QMAKESPEC=win32-msvc2010


    Note that you also use win32-msvc2010 for x64. This is a folder name (see below)
     
  5. If you need to change some compilation options, edit them in the qmake.conf file found under:

      C:\Qt\4.7.4\mkspecs\win32-msvc2010

    For example, you will edit the file to change the wchar_t option from -Zc:wchar_t- to -Zc:wchar_t (i.e. removing the "-" at the end) because msvc2010 compiles code with wchar_t defined as a native type by default, but Qt is still setup to use a typedef instead. You may also want to change the exception model (look in the configuration flags, you will find -EHsc by default in 4.7.4 and maybe you'd rather have -EHa or -EHs)

    Note that you should avoid changing flags that are otherwise available on the configure command line (see the -help option for more info.)

    Note: Here you recognize the name used in the QMAKESPEC variable.
     
  6. Update PATH variable to include %QTDIR%\bin
     
  7. Start Visual Studio 2010 Command Prompt. This is where you choose 32 bits or 64 bits:

    32 bits (x86) you start the standard prompt:
    Start > All Programs > Microsoft Visual Studio 2010 > Visual Studio Tools > Visual Studio Command Prompt (2010).

    64 bits (x64) you start the 64 bit prompt:
    Start > All Programs > Microsoft Visual Studio 2010 > Visual Studio Tools > Visual Studio x64 Win64 Command Prompt (2010).
     
  8. Run following commands in it (every line is a different command: type it then press Enter):
      cd c:\Qt\4.7.4
      configure -debug-and-release -opensource -platform win32-msvc2010
      nmake
    Note that the configure includes many options. A few I would suggest you look into:

    -qtlibinfix=<name>   Change the Qt library names from the default to something like QtCore<name>.dll — this allows you to create a libarry with a name specific to your application which under Microsoft is certainly a good idea (i.e. to avoid conflicts with other applications.) For example, I could use -qtlibinfix=4Alexis so the libraries look like QtCore4Alexis.dll.

    -qtnamespace=<name>   Add namespace <name> too all the files. This means you'll need to use that <name> any time you acces a declaration from Qt, but it could help you if you otherwise have conflicts. For example, -qtnamespace=Qt forces you to use Qt::QApplication instead of just QApplication.

    -static   Generate static libraries instead of shared libraries. This makes for bigger executables, but prevents DLL hell problems without having to rename the libraries. Note that will not resolve potential namespace problems.

    -help   Display a very long list of all the available configuration options.
     
  9. Download and install Qt Visual Studio Add-in (this has moved, I do not know where).
     
  10. Run Visual Studio 2010. Integrate just compiled Qt to IDE using menu Qt > Qt Options > Qt Versions > Add
     
  11. To clean the files left behind, use
      nmake clean

So, I updated a couple of things as available in the comments. These should work as is for you... Good luck!

Compilation Errors

There is one type of error I often get. While compiling, once in a while the linker emits an error saying it cannot open a file (.DLL or some other file.) This can be because you have an anti-virus system that checks the file too soon, before the linker is done.

Known conflicts

There is one well known conflict in Qt: the term signals is a #define which means that any other library using that term cannot work with Qt (at least not without a wrapper of some kind.)

The one library that makes use of the term is boost::signals.

To avoid the problem, simply make use of boost::signals2 which was renamed in part to avoid the problem with Qt, but also is a much more advanced version of the signals library.