43

What steps should I take to compile Qt (version 4.8.x) for Visual Studio 2012?

I already carefully followed the instructions in the accepted answer of this question (which is for VS 2010), but WebKit module failed to compile (I'm not sure if the error message was logged anywhere during compilation).

I also saw this question which asks the same, but for VS 2012 RC (which is why I thought this wouldn't be a duplicate question). Furthermore, the answerer says he has compiled Qt for VS 2011 Beta, so there's a chance it may not work for VS 2012 (RTM). The compilation takes a lot of time, which is why I have not tried it yet.

At least one problem I realized is that there's no win32-msvc2012 directory in Qt\mkspecs. Should I just create that directory and copy the files from win32-msvc2010, possibly with some modifications?

Another sub-question is whether I should make some modifications to Qt sources before starting compilation.

Community
  • 1
  • 1
Smi
  • 13,850
  • 9
  • 56
  • 64

3 Answers3

72

Qt 4.8.3 with Visual Studio 2012 x64 (should also work with 4.8.2)

  1. Install Strawberry Perl

  2. Download Qt 4.8.3 source code from http://qt-project.org/downloads

  3. Go to mkspecs\win32-msvc2010. Open qmake.conf and change:

    QMAKE_COMPILER_DEFINES  += _MSC_VER=1600 WIN32
    

    to:

    QMAKE_COMPILER_DEFINES  += _MSC_VER=1700 WIN32
    
  4. Replace qt-everywhere-opensource-src-4.8.3-x64\src\3rdparty\webkit\Source\JavaScriptCore\wtf\HashSet.h by this HashSet.h.

  5. Start "VS2012 x64 Native Tools Command Prompt"

  6. Switch to Qt 4.8.3 source directory (the directory that contains configure.exe)

  7. Run:

    configure -mp -opensource -nomake demos -nomake examples -platform win32-msvc2010
    
  8. Followed by:

    nmake
    

I programmed a tool called BlueGo which automatically downloads Qt 4.8.3 and builds it with VS2012 x64: http://bluego.vertexwahn.de (also works with VS2010 x64) (it just does what I described above automatically)

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
  • Strawberry Perl? Is that if I want to use your tool? – JJacobsson Nov 07 '12 at 07:41
  • 1
    You have to install Strawberry Perl (http://strawberryperl.com/) if you want to use my tool to build qt (because it is needed to build qt) - the new version of my tool which will be released the next days will check before the build button is hit if Perl is installed. – Vertexwahn Nov 07 '12 at 23:20
  • A couple of quick notes: 1) thank you for this **awesome** answer, saving me a lot of time 2) you can use ActiveState Perl instead of Strawberry Perl - either works. – Nathan Osman Nov 26 '12 at 07:12
  • @Vertexwahn For clarification, is Strawberry Perl absolutely necessary to build Qt with VS2012 or can steps 2-8 be done without it? Additionally, I shouldn't need the hash set because I'm using -no-webkit? – rem45acp Dec 20 '12 at 22:51
  • Additionally, for me qt creator said the binaries were incompatible between x86 and x64 when specifying qt version? – rem45acp Dec 21 '12 at 03:26
  • @rem45acp The perl command needs to be available - if you do not have a perl installation steps 2-8 will fail. I am not sure if hash set needs to be fixed when building with –no-webkit. I do not use the qt creator – I use CMake, VS2010/12 together with Qt – so I can also not help you with your Qt creator issue – Vertexwahn Jan 01 '13 at 18:09
  • 2
    It worked for me, even though I don't have a Perl package installed on my system. Just needed to patch the file. – neuviemeporte Apr 25 '13 at 08:55
  • We still have to apply HashSet.h patch even with Qt 4.8.6 and VS2012 – Arun Jul 23 '15 at 01:11
  • @Androidcus No. You have to apply several patched before you can build Qt 4.8.3 using VS2013. Use Qt 5.6 alpha if this is possible for you. – Vertexwahn Jan 21 '16 at 12:55
22

Qt 4.8.4 needs less tweaking than described by Vertexwahn above.

  • The HashSet still has to be fixed (see fix of Vertexwahn) after Qt has been extracted from archive.
  • Platform win32-msvc2012 is supported out-of-the-box though (also works for 64bit in the 64bit environment, don't ask why they name it Win32).

So simply replace the HashSet.h and compile.

Smi
  • 13,850
  • 9
  • 56
  • 64
cbielow
  • 416
  • 4
  • 3
  • 9
    `Win32` is used as an OS API platform: the Win32 API is available on all Windows desktops (x86, x64, and previously 64-bit Itanium). 64-bit doesn't need a different toplevel configuration, so to keep things compatible they kept the name. – rubenvb Dec 19 '12 at 12:18
6

Just creating a win32-msvc2012 directory with the changes below didn't work for me, there is more editing necessary. What exactly is necessary is described in the thread you already linked.

What I did, I went to win32-msvc2010.

There, open qmake.conf and change

QMAKE_COMPILER_DEFINES += _MSC_VER=1600 WIN32

to

QMAKE_COMPILER_DEFINES += _MSC_VER=1700 WIN32

Then I could configure using win32-msvc2010.

Also, I used these changes: http://qt-project.org/forums/viewthread/17771 (alzi's Version)

Flo
  • 61
  • 1
  • 2
  • When you say "Then I could configure using win32-msvc2010" do you mean win32-msvc2012? When I did this in a x64 command prompt qt creator would not compile due to the difference in architecture and compilers. – rem45acp Dec 21 '12 at 03:30