How To Compile Qt 4.7 with Visual Studio 2010

Usual way of installing Qt for Visual Studio is to download already compiled binaries from Nokia website. However binaries for the latest Visual Studio 2010 are not available (on the moment of writing).

This post is a step-by-step guide on how to compile Qt 4.7.1(3,4) with MSVC 2010.

April 5, 2012: As reported by Snouty, 32bit version of Qt 4.8.1 has been successfully compiled by this guide.
December 20, 2011: As reported by Evon, 64bit version of Qt 4.8.0 has been successfully compiled by this guide. To do 64bit compilation, please use Visual Studio x64 Win64 Command Prompt (2010) in step 8. Also please use jom 1.06 and don’t forget to install Service Pack 1 for Visual Studio.

September 16, 2011: Qt 4.7.4 has been successfully compiled by this guide.
August 14, 2011: In order to build Qt for 64 bits just use Visual Studio x64 Win64 Command Prompt (2010) in step 8. Also install Service Pack 1 for Visual Studio 2010 beforehand – it fixes few bugs related to x64 compilation.
July 18 2011: Qt 4.7.3 and Qt 4.8 (beta) has been successfully compiled by this guide. Just replace version number where applicable.

  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. Install Perl if you are going to compile Qt >= 4.8.0
  3. Download and extract Qt 4.7.1 Source Code. (Or Qt 4.8.0).
  4. Copy contents of the folder qt-everywhere-opensource-src-4.7.1 to the directory where you intend to install Qt. In our case this is C:\Qt\4.7.1.
  5. Set up environmental variables
    QTDIR=C:\Qt\4.7.1
    QMAKESPEC=win32-msvc2010
  6. Update PATH variable to include %QTDIR%\bin
  7. Download the latest version of jom.
  8. Extract jom files to C:\Qt\jom folder
  9. Start Visual Studio 2010 Command Prompt:
    Start > Programs > Microsoft Visual Studio 2010 > Visual Studio Tools > Visual Studio Command Prompt.
  10. Run following commands in it (every line is a different command: type it then press Enter):
    cd c:\Qt\4.7.1
    configure -debug-and-release -opensource -platform win32-msvc2010
    ..\jom\jom.exe -j N

    Where N is number of CPU cores you want to utilize for Qt compilation. Larger is better.

  11. Download and install Qt Visual Studio Add-in.
  12. Run Visual Studio 2010. Integrate just compiled Qt to IDE using menu Qt > Qt Options > Qt Versions > Add

Usually compilation takes about 10 hours, but thanks to jom and Intel SSD drive it took only 2 hours 40 minutes on my machine (Windows 7, 64bits)

Remarks

* Jom is nmake replacement for Qt compilation on multi-core CPU. Its parameter -j N allows to setup number of parallel processes for compilation. Number of physical CPU cores is a good choice for N.

** Do not forget to use /d switch if you want to change drive in command prompt, e.g: cd /d d:. Usual cd d: does not work anymore – a little “surprise” from Microsoft.

Contributions

* As Evon pointed in comments, Qt folder has huge size (approx. 7GB) after compilation. One can safely shrink its size by deleting temporary files created during the process. Once compiled Qt doesn’t depend on these intermediate files – and they can be erased without affecting Qt functionality. Run as last command in step 9:

..\jom\jom.exe clean

Note that PDB files will be deleted too.

** Rob provided his compilation script based on nmake with multi-core support.

1 Star2 Stars3 Stars4 Stars5 Stars (37 votes, average: 4.95)
Loading ... Loading ...

116 Comments

  1. Argo
    Posted February 15, 2011 at 1:19 pm | #

    I followed the steps and it worked like a charm!
    Thank you!

  2. Simon
    Posted February 15, 2011 at 6:13 pm | #

    Tip: Make sure you have the requirements installed:

    (Perl, DirectX SDK & Windows Server 2003 R2 Platform SDK)

    http://doc.trolltech.com/latest/requirements-win.html

    • Posted February 15, 2011 at 7:12 pm | #

      Thanks for suggestion!

      • Joko
        Posted June 2, 2011 at 8:24 am | #

        When I give the command \jom\jom.exe -j 4 , it gives error saying that no makefile found. what to do? pl help…!

        • Franz
          Posted July 28, 2011 at 1:45 am | #

          The command is ..\jom\jom.exe and assumes that jom.exe is in folder C:\Qt\jom. The Makefile can be found in C:\Qt\4.7.3 (or similar).

  3. Simon
    Posted February 15, 2011 at 7:01 pm | #

    And make sure you compile it trough the Visual Studio Command promt, i forgot this step and couldn’t get it to work. (Couldn’t find nmake)

    Start > Programs > Microsoft Visual Studio 2010 > Visual Studio Tools > Visual Studio Command Prompt

    • Posted February 15, 2011 at 7:13 pm | #

      That is 9th step. Maybe I have to stress it more.

  4. Ben
    Posted February 18, 2011 at 4:55 pm | #

    Is there or will there be a binary installer for msvc 2010 anytime soon? I am a student and would love to start learning Qt myself, however no matter what I try I get errors. Usually the error is labeled “Return code 2″ or “Return Code 31.” On occasion there is an error with QProcess. This occurs using both jom and nmake. Any information regarding my (granted vaguely described) errors or whether or not a binary installer may be coming out is greatly appreciated. Thanks for your time.

    • Posted February 18, 2011 at 5:01 pm | #

      I have no idea about installer for MSVC 2010. Unfortunately I do not know how to solve QProcess errors too. Sorry, I didn’t encountered them.

      • Ben
        Posted February 19, 2011 at 5:59 am | #

        Well thank you for your speedy response. If I find a solution, I shall let you know.

      • SaiGo
        Posted December 21, 2011 at 10:03 am | #

        I had the same problem, but I ran the instructions in Windows Safe Mode Networking and that resolved this problem. No other change. FYI, mine is a Windows 7, msvs 2010, 32 bit, running on i5. Tip: it took me several hours to run “..\jom\jom.exe -j 4″ command. Good luck.

    • Alex
      Posted February 19, 2011 at 6:02 am | #

      about “return code 2″
      see on environmental variables, PATH and on install Qt Visual Studio Add-in 1.1.7
      I write PATH – C:\Qt\4.7.1\bin

  5. Alex
    Posted February 19, 2011 at 5:56 am | #

    I do all
    but finally in vs doesn’t include qt files
    for example QApplication
    what I must do?

    • Alex
      Posted February 19, 2011 at 6:03 am | #

      I make Qt without error

  6. Matt
    Posted February 19, 2011 at 2:51 pm | #

    Thanks, help me a lot.
    jom does the job well

  7. Mr X
    Posted April 29, 2011 at 6:31 am | #

    In instruction 10, is “\jom\jom.exe -j 4″ right after the platform option? Or is it on a new line? Where does the preceding “..” come from?
    Also, when I run that command, without this last part (i.e. “..\jom…” part) I get this error:

    cpdir: Failure to create “C:/Qt/4.7.1/mkspecs/default”
    Couldn’t update default mkspec! Does C:/Qt/4.7.1/mkspecs/win32-msvc2010 exist?

    Any idea how to get around this?

    Thanks,

    • Posted May 3, 2011 at 1:40 pm | #

      @”In instruction 10, is “..\jom\jom.exe -j 4″ right after the platform option?”
      No, it is on a new line (press Enter after -platform win32-msvc2010, type ..\jom\jom.exe -j 4 and press Enter again)

      • Tomm
        Posted July 30, 2011 at 4:56 am | #

        I’m trying to compile 4.7.3 for VS2010 using your method. I get to the “configure -debug-and-release -opensource -platform win32-msvc2010″ line and hit enter, but it asks me to confirm the license, so I do, and it starts going without me having chance to enter “..\jom\jom.exe -j 4″. Is this the usual behaviour?

        Thanks

        • Tomm
          Posted July 30, 2011 at 5:40 am | #

          Ah NVM, I didn’t realise it had to do some configuration before compilation could begin, it’s going as I type this. Cheers for the great tutorial, I’ve had nothing but problems getting QT working with VS2010, so I’m hoping this works. Cheers for the great tutorial.

  8. M.Hatami
    Posted May 4, 2011 at 5:14 pm | #

    Very interesting article , but I was searching to see any success with Static Build of qt. !?
    I did my best with 4.8 (new Version from Git repository) but problem is that the ABI is not yet recognized even with latest QtCreator from gitorious repository.

    did you had any luck with Static build ?

  9. Pavel
    Posted May 7, 2011 at 6:43 pm | #

    I believe it is possible to make it fast with nmake if “configure -mp” is used. In this case multicore features of jom have no bonuses compared to standart nmake.
    (Default configure key is -no-mp which means no use of multiple processors for compiling with MSVC)

  10. louis
    Posted May 9, 2011 at 4:50 pm | #

    Hi, i am using visual studio 2010, why am i unable to find visual studio tools? any help pls? what i have is only visual studio tools for office

  11. Confused
    Posted June 4, 2011 at 12:37 am | #

    Hi,

    I’ve been trying to build Qt using MS VS 2010, and running into failures.
    I’ve tried using nam and jom, and both have failed.
    I’ve set the environment variables for QTDIR, QTMAKESPEC and PATH per my
    installation of Qt (in D:\4.7.3).

    I’ve included the output from jom, below.

    Can someone help?
    thanks,
    -Confused

    ——————————————————————–

    d:\Qt\4.7.3>..\jom\jom.exe -j 4

    jom 1.0.5 – empower your cores

    Microsoft (R) 32b/64b MIDL Compiler Version 7.00.0555
    Copyright (c) Microsoft Corporation. All rights reserved.
    testcon.idl
    ocidl.idl
    oleidl.idl
    objidl.idl
    unknwn.idl
    wtypes.idl
    basetsd.h
    guiddef.h
    oaidl.idl
    servprov.idl
    urlmon.idl
    msxml.idl
    oaidl.acf
    ocidl.acf
    Microsoft (R) 32b/64b MIDL Compiler Version 7.00.0555
    Copyright (c) Microsoft Corporation. All rights reserved.
    testcon.idl
    ocidl.idl
    oleidl.idl
    objidl.idl
    unknwn.idl
    wtypes.idl
    basetsd.h
    guiddef.h
    oaidl.idl
    servprov.idl
    urlmon.idl
    msxml.idl
    oaidl.acf
    ocidl.acf
    command failed with exit code 31
    command failed with exit code 2
    command failed with exit code 2
    command failed with exit code 2
    command failed with exit code 2

    d:\Qt\4.7.3>

  12. flyingcadet
    Posted June 8, 2011 at 12:43 am | #

    For an almost always guaranteed compile, download the binary release for VS2008 from qt.nokia.com

    I’m developing in VS2005. Currently rebuilding my 4.7.1 build (got an itchy uninstall finger). I’m about to do this for the 4.7.3 update.

    Why? it comes with DLL forms and the source code for all the 3rd party packages, which allows for it to link correctly. You won’t have to worry about the 3rd party packages being the wrong version for your build, either.

    to do this, here are the appropriate addendum for this article (also,I’m directing to the 4.7.3 build, but everything should be the same):

    Follow OP’s first two steps.

    3: Download Qt libraries 4.7.3 for Windows (VS 2008, 228 MB)

    4: Execute the installer. Notice that Qt will be installed in C:\Qt\4.7.1

    continue on with step 5 from above.

    Thanks for the information (it’s been a few months since I had to build Qt).

    flyingcadet

  13. BugFeature
    Posted June 21, 2011 at 3:16 am | #

    Hello Confused!

    I had the same problem as you have. I set also the environmental variables, as mentioned above, and I got the same errors like you.
    (By the way – my system is Windows 7, Visual Studio 2010 Ultimate, Qt 4.7.3 – could be important, maybe.)

    Ok. I deleated every environmental variable concerning Qt, started the VS2010 comm. prompt again. When the comm. prompt is open, one can see in the most upper line that there is no error – everything about Visual Studio 2010 was loaded.
    Next step is to configure Qt with (my choice)

    configure -platform win32-msvc2010 -opensource -no-qt3support

    After the configuration, nmake! I am compiling it right now without problems. Few hours later, Qt will be compiled. So, maybe now or not one has to set the variables. I will try it first without setting the variables. If any problems occure there, I will do further steps.

    I hope, that I was able to help you/anyone.

    Best regards

  14. auhoss
    Posted August 14, 2011 at 12:09 pm | #

    Very well written instructions, and that is a rare thing these days. Nice job!

  15. auhoss
    Posted August 14, 2011 at 1:19 pm | #

    A follow up comment. I believe your instructions will produce a 32 bit Qt build since you are stating to use [Visual Studio Command prompt] vs the x64 command prompt. Is this correct? The way you have it written appears to work, but it is causing all kinds of problems with VTK, which is expected 64 bit Qt libs. I tried simply using the x64 command prompt but keeping all other steps the same. The jom is failing for x64. Ideas?

    • Posted August 14, 2011 at 9:43 pm | #

      Yes, you are right, this is 32 bits build.

      And yes, you are correct again – in order to compile x64 binaries just use Visual Studio x64 Win64 Command Prompt (2010).

      However, make sure that:
      1. You have installed Service Pack 1 for Visual Studio 2010. Otherwise it won’t build x64 projects correctly.
      2. You do clean build. Copy Qt sources (from downloaded zip file) to another directory and compile it there for x64.

      I’ve just compiled Qt 4.7.3 for x64 platform this way – no problems with jom appeared.
      Test applications run nicely too. Dependency Walker re-assures that binaries are indeed x64 binaries.

      • Nic
        Posted November 22, 2011 at 8:33 pm | #

        Hi!
        first of all thanks for this!
        I would ask you if I should change something in the instructions in case I want to build the 64bit version.
        I work with windows 7, VS 2010 with SP1, and Qt 4.8.0

        Thank you very much.

        • Posted November 22, 2011 at 10:34 pm | #

          Just use x64 Win64 Command Prompt. No other modifications are needed. I’ve compiled 4.7.3 without problems for x64. I’m sure 4.8.0 is similar.

          • Nic
            Posted November 23, 2011 at 11:10 pm | #

            Thank you for the prompt reply. I tried to build the 4.8.0 but I had some problems/errors with jom, probably because I’m working with windows 64bit. So I moved to the 4.7.4 and it worked fine.

            Thanks again!

  16. Max
    Posted August 16, 2011 at 12:27 am | #

    I really need help….

    After I run: configure -debug-and-release -opensource -platform win32-msvc2010
    I get these messages:
    Creating qmake…
    execute: File or path is not found (nmake)
    execute: File or path is not found (namke)
    Cleaning qmake failed, return code -1

    As a result when I try to run ..\jom\jom.exe -j 4 I get:
    Error: File Makefile doens`t exist.

    I am using VS 2010 Command Prompt. The weird thing is when I type in nmake he doesn`t have a clue what it is. Could I be missing something…?

    • Posted August 16, 2011 at 1:26 pm | #

      My only guess your VS 2010 is not properly installed.

    • Anonymous
      Posted October 14, 2011 at 12:15 am | #

      I’am having the same problem exactly as you. I’m running Windows 7 64-bit BTW. Did you solve your problem?

      • Posted October 14, 2011 at 9:17 am | #

        I suspect VS Commnad Prompt Tools are not properly installed on your system.

        Try to run vsvars32.bat in a command prompt. It is located here:

        C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\

  17. Kurt
    Posted August 17, 2011 at 3:25 am | #

    Under step 9, is the third line supposed to be part of line 2? Because it appears that I never had the option to use Jom? I hardly ever use the command prompt so if line 3 was supposed to be part of line 2 that needs to be clarified. It just started doing stuff right after I hit the enter key after msvc2010.

    • Posted August 17, 2011 at 9:13 am | #

      On step 9 every line is a different command. I’ve added clarification – thank you for your feedback.

  18. Jaykob
    Posted August 18, 2011 at 2:58 am | #

    Compilation with jom brought up a linker error. Compilation with nmake was successful!

  19. Kurt
    Posted August 21, 2011 at 1:50 pm | #

    Worked like a charm!

    I am trying to compile and run these samples http://qt.gitorious.org/qt-solutions/qt-solutions/trees/master/qtwinmigrate but failing. Believe it may be because have to compile qtwinmigrate with Visual Studio. Any pointers on how to do that?

    Thanks so much, Kurt

  20. Michael
    Posted August 28, 2011 at 6:18 pm | #

    I’ve followed all the steps, and now I’m wondering about the last one – how to integrate? In Qt menu I have only: ‘Launch Designer’,'Launch Linguist’,'Open QT Project File…’, and ‘Qt Options’ available. Is this ok?

  21. Posted September 20, 2011 at 9:17 am | #

    Hi Pavel,

    These instructions are perfect – I have been able to build Qt and create projects via VS 2010 with ease.

    I do have one question: Due to project requirements on deployment, I built Qt as static instead of shared (you haven’t specified it in your configure parameters, but the default setting is shared). This way, I don’t have to deploy the Qt dll’s as well.

    However, I observe that the release libraries are built with the -MD flag (Multi-threaded DLL). How do I force it to use the -MT flag instead? The configure script seems hardcoded to use this flag when -static is passed for configure.

    Was hoping you might have a quick answer here, would rather not read through a 5000 line config script…

    Thanks!

    • Posted September 20, 2011 at 9:19 am | #

      Oh and one other thing – I’d like to change it to use “treat TCHAR as a built-in type” – again the script seems hardcoded to always pass FALSE for that flag (“Z:wchar_t-”).

      Any thoughts?

    • Posted September 20, 2011 at 9:32 am | #

      You can change compiler options directly using file Qt-folder\mkspecs\win32-msvc2010\qmake.conf.
      Here are few related options from the file:

      QMAKE_CFLAGS            = -nologo -Zm200 -Zc:wchar_t-
      ...
      QMAKE_CFLAGS_RELEASE    = -O2 -MD
      QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
      QMAKE_CFLAGS_DEBUG      = -Zi -MDd
      ...
      

      As for static vs. shared – I would advise to use Qt DLL. As far as I understand it is the most correct and safe way of using LGPL library in commercial application.

      • Posted September 20, 2011 at 10:21 am | #

        Wow, that was fast – thanks!

        Wrt static/shared – The source of my application would be redistributed under either GPL 2 or LGPL 2 – would that still indicate using the DLL’s? My understanding is if I also make my app open source, static linking is fine.

        • Posted September 20, 2011 at 10:51 am | #

          @”My understanding is if I also make my app open source, static linking is fine.”
          Yes, I think so too.

  22. Vinod
    Posted October 10, 2011 at 7:31 pm | #

    I have installed Qt SDK. I did n’t find any specific QTDIR folder.
    In the QtSDK/Desktop/Qt/4.7.4/ folder I found mingw and vs2008.
    What folder should i mention for QTDIR

  23. Michael
    Posted October 17, 2011 at 7:47 pm | #

    Hi!
    I had a couple issues, but by the fourth time I finally made it.
    What helped was redoing everything on a freshly unpacked Qt Source Code, also I did run “vcvarsall.bat” from MS Visual Studio 2010 which I think helped the issue of some errors (return code 2 maybe). Jom is really great!
    Thanks!

  24. Evon
    Posted October 19, 2011 at 8:29 am | #

    Great instructions! I followed them to successfully build 64bit Qt 4.7.4 on my Win7 Pro x64 machine. My version’s usable both within Qt Creator 2.3.0 (32bit) and Visual Studio 2010 (SP1). Both IDEs can build 64bit applications! It’s definitely worthwhile to update Visual Studio to Service Pack 1 prior to compiling Qt, as my builds continued to fail until I updated.

    Here’s my config, for variety:

    configure.exe -debug-and-release -opensource -platform win32-msvc2010 -no-qt3support -qt-gif -qt-libpng -qt-libmng -qt-libtiff -qt-libjpeg

    I have noticed that the Qt folder is enormous after compiling. I’d like to delete the intermediate files that bloat the folder while leaving the compiled 64bit libraries intact. I read here and here about 3 options with nmake (clean, confclean, distclean), but I’m unsure what exactly the difference is between each.

    As I understand it, one deletes the intermediate files, one deletes the intermediate files AND the compiled libraries, and one deletes the intermediate files AND the source code… but which one’s which? Can you shed some light on the differences between the 3 options?

    • Evon
      Posted October 19, 2011 at 8:31 am | #

      I also haven’t found anything about using jom to “clean” my Qt build folder. Does jom have an alternative to any/all of the nmake ___clean options?

      • Posted October 19, 2011 at 10:15 am | #

        I appreciate your feedback, thanks.

        You are right, Qt folder is pretty big after compilation since many temporary files were created in the process.
        Once compiled Qt doesn’t depend on these intermediate files – and they can be safely erased without affecting Qt functionality.

        Run as last command in step 9:

        ..\jom\jom.exe clean

        I’ll added this to the manual. Thanks!

        • Evon
          Posted October 20, 2011 at 1:24 am | #

          Thanks for the tip! Unfortunately, running jom’s clean happens to also cause the VS2010 compiler to throw LNK4099 warnings because of vc100.pdb being deleted in all of the Qt source libraries. I believe in fixing errors, not ignoring them. Do you know of a way to prevent this?

          Here’s the error text for a simple project:
          qtmaind.lib(qtmain_win.obj) : warning LNK4099: PDB ‘vc100.pdb’ was not found with ‘qtmaind.lib(qtmain_win.obj)’ or at ‘C:\dev\programs\AddressBook\vc100.pdb’; linking object as if no debug info

          • Posted October 21, 2011 at 9:44 am | #

            “Warning” is what it is – warning, not error.

            Debug information (pdb) for Qt is needed only in rare cases (e.g. for debugging Qt itself) and not crucial for apps development – you can debug them as usual.

            Just for analogy – MS doesn’t supply pdb files for Windows kernel modules :-) which is intensively used in any application.
            Nonetheless this is not the “error” preventing development for Windows – right?

            PDB files are of the largest size among temporaries generated by compiler. If you keep them – no space saving will be available.

          • Evon
            Posted October 25, 2011 at 2:53 am | #

            Thanks for the comment. I’ve messed around with it since my last post and you are correct in saying that that warning has no apparent ill effect on the Qt program. I’ll have to disable that warning at some point when I get tired of seeing it. :-)

            Additionally, the 64bit Qt also works in the 32bit Qt Creator IDE (v2.3.1 on a clean install, NOT the Sept 1, 2011 SDK). Just add it to your list of Qt versions in Tools -> Options. To debug your 64bit programs on a PC, you have to download and install the free 64bit Debugging Tools for Windows as instructed on the official Nokia site here and here.

            I was relieved to learn that I didn’t have to compile a 64bit version of Qt Creator to do 64bit development.

          • Posted October 25, 2011 at 9:32 am | #

            Good news, Evon! Thanks for the info.

            I prefer to use MSVC 2010 IDE + Qt Visual Studio Add-in + Visual Assist X combination. IMHO Qt Creator IDE slow and immature, but it has major advantage of being free.

            I guess you already own Pro version of VS 2010 (since you can compile x64) – so why don’t you use it for development?

            P.S. I’m impressed by the work of WatershedSciences.com company. I worked on similar projects here in Japan for AeroAsahi company. I developed compression algorithms for data from laser measurement & huge aerial images. Earth is pretty small after all.

          • Evon
            Posted October 28, 2011 at 6:54 am | #

            The newer versions of Qt Creator are pretty fast and the auto-generated code from integration of Qt Designer into Qt Creator can be helpful. I generally like to code my own UI with Qt and avoid Qt Designer altogether, but I’m still playing with it once in a while.

            I haven’t toyed much with the VS Add-in yet since Qt Creator is simpler to use for a casual coder such as myself.

            Interesting that you’ve heard of us over in Japan! We’re always interested in new opportunities. :) I just did a little work over there this summer for my research with Oregon State Univ as a tsunami-related collaboration with BRI. Small world.

          • Ryan
            Posted November 28, 2011 at 3:28 am | #

            Awesome tutorial, very concise and well written! I just built from scratch with MSVC2010 in the Visual Studio x64 Command Prompt and it generated the proper qmake for x64 development (as you pointed out Pavel, no adjustments to the tutorial are needed). If I had read the prereqs a little closer I would have gotten it on the first try.

            However I am still curious about this (from Evon):
            “Additionally, the 64bit Qt also works in the 32bit Qt Creator IDE (v2.3.1 on a clean install, NOT the Sept 1, 2011 SDK). Just add it to your list of Qt versions in Tools -> Options”

            I had tried this with the binaries from Qt and could not set my x64 compiler in this way because I did not have the proper qmake (and thus Qt greys out the x64 toolchain in the projects tab). Can you give me some suggestions as to why this was happening? I guess I don’t know much about the difference in the qmake files for x64 and win32 compilers. My computer config was the same before I built and when I tried this last (I had installed all the build prereqs before this). Thanks.

          • Evon
            Posted November 30, 2011 at 2:07 am | #

            @Ryan:
            I’ve noticed that Qt Creator saves its Qt4 settings separate from its installation so that you can share your toolchains between multiple QtC installations. There might be some sort of corruption between versions. More likely, though, one of the links in your toolchain is broken.

            First, I’d check to make sure that you’re targetting the proper qmake. If you move your build directory after following Pavel’s steps, then you will break the toolchain even if you’re targetting the correct qmake. For me, that’s
            C:\dev\qt\4.7.4_x64_msvc2010\bin\qmake.exe
            Note that this is the exact same directory where I built my 64bit version of Qt—I’ve never moved it.

            Second, make sure you create a new toolchain under Tools->Options->Qt4 rather than editing an existing one to prevent corruption. Click down the Details and make sure you click [Build All] to construct your toolchain. If you’ve already done that, make sure it’s pointing to the correct directory and using the “Microsoft Visual C++ Compiler 10.0″ (or whatever version you have installed).

            Third, I deleted all of my *.pro.user files for the projects that I wanted to build in 64bit and recreated the build configurations, just to make sure that I had clean projects going. I doubt this is your problem since it won’t even enable your toolchain, but you never know.

            PS—Pavel, I linked your site from Nokia’s wiki and overhauled their instructions since their 64bit compilation instructions were laughable. You might see a traffic boost.

          • Posted November 30, 2011 at 9:38 am | #

            Evon,
            Thank you for your valuable advises and for spreading the word!
            Nokia’s wiki is a top referrer to the page for the last 7 days.

  25. Sascha
    Posted October 24, 2011 at 11:30 pm | #

    Hello,

    thanks for the great tutorial. Everything worked well, but after roundabout 1:30 hours of compiling, I got the following error :

    moc_helpgenerator.cpp
    link /LIBPATH:”c:\Qt\4.7.1\lib” /LIBPATH:”c:\Qt\4.7.1\lib” /NOLOGO /INCR
    EMENTAL:NO /SUBSYSTEM:CONSOLE /MANIFEST /MANIFESTFILE:”tmp\obj\release_shared\qh
    elpgenerator.intermediate.manifest” /OUT:..\..\..\..\bin\qhelpgenerator.exe @C:\
    Users\Sascha\AppData\Local\Temp\qhelpgenerator.exe.3288.1030.jom
    LINK : fatal error LNK1104: Datei “..\..\..\..\bin\qhelpgenerator.exe” kann nich
    t ge÷ffnet werden.
    command failed with exit code 1104
    command failed with exit code 2
    command failed with exit code 2
    command failed with exit code 2
    command failed with exit code 2
    command failed with exit code 2

    c:\Qt\4.7.1>

    “qhelpgenerator.exe cannot be opened”… and the compiling stopped. Someone got an idea whats the matter about that?

    Thank you very much for your help!
    Sascha

    • Posted October 25, 2011 at 9:35 am | #

      Hi, Sascha!

      It seems something wrong with your PATH – check 5th step in tutorial.
      BTW, try to compile latest version of Qt 4.7.4 – no reason to use old one 4.7.1.

    • Oli
      Posted October 29, 2011 at 10:42 am | #

      I had an issue where the build failed in the middle on my 64 Bit Windows 7 Pro Laptop using Developer Studion 2010 Pro. I can’t remember the exact error but it seems similar to this one. Running the command prompt as an administrator solved the issue.

      Also to clarify, I was building the 32 bit version using the x86 command prompt.

      Pavel, great job,

      Oli

  26. Rob
    Posted October 28, 2011 at 4:04 am | #

    Jom is ok, but you can just use the -mp switch with nmake.

    Here’s my script to do an out of source build on the latest git located in C:\Qt\qt-git-build

    @ECHO OFF
    rmdir /Q /S C:\Qt\qt-git-build
    mkdir C:\Qt\qt-git-build
    cd C:\Qt\qt-git-build
    ..\qt-git\configure -opensource -mp -qt-zlib
    nmake
    nmake qdoc3
    editbin /STACK:0x200000 bin\qdoc3.exe
    nmake docs
    nmake install
    nmake clean
    cd ..

    Just open up a Visual Studio x64 command prompt and run the batch file. This also builds the docs, the editbin command fixes a stack overflow that none of the developers seem to care about because it only shows up in 64-bit windows. The nmake install copies the header files over instead of dummy files to the qt-git directory, and the clean gets rid of the temporary files. This builds a nice copy of Qt that you can move from computer to computer, albeit pretty large.

    Our development environment requires x64 because of our large datasets, and I’m already using functions that were introduced in 4.8.0. This will have to do until the people at the qt-msvc-installer google code page upload 4.8.x version of their installer.

    @Evon: The Qt Creator which you download from the Nokia website has Qt built statically. Check the ‘about’ section and you’ll see it may be using a different version.
    The whole process takes about 2 hours with an i7, no jom necessary.

    • Posted October 28, 2011 at 9:53 am | #

      Thanks for great info and for sharing your script!
      I’ve added link to you comment on the page.

      Just to note – Qt compiled by my instructions can be moved from one computer to another without any problems too.
      Webpage of qt-msvc-installer says about Visual Studio 2008 support only. As for docs – I use online help – it is always up to date and broadband is spoiling :-) .

  27. Luke
    Posted October 29, 2011 at 3:23 am | #

    Worked like a charm, even if I launched ..\jom\jom.exe -j 4 having dual-core machine.

  28. Luke
    Posted October 29, 2011 at 4:21 am | #

    Pls help. For my compilation I used QMAKESPEC=win32-msvc2010, then configure -debug-and-release -opensource -platform win32-msvc2010.
    I am on x64 machine, so I used Visual Studio x64 Win64 Command Prompt for whole process.
    Now when trying to launch simple app created from VS wizard in Debug configuraion Win32, I got:

    >QtGuid4.lib(QtGuid4.dll) : fatal error LNK1112: module machine type ‘x64′ conflicts with target machine type ‘X86′

    So the Qt is builded for x64 even if win32-msvc2010 was set? Because of the x64 command prompt? Or am I wrong? My orded was to develop x86 app onx64 system. Thanks.

    • Posted October 29, 2011 at 10:29 am | #

      You need x86-Qt to create x86 applications even using x64 operating system for development.
      So, compile Qt in x86.

      Yes, when you use x64 command prompt Qt is compiled to x64, despite win32-msvc2010 setting.

      • Luke
        Posted October 30, 2011 at 6:59 am | #

        Yippee! It works. Thanks a lot for reply.
        Visual Studio Command Prompt makes it x86, Visual Studio x64 Win64 Command Prompt (2010) makes it x64.

        First time I tried the x86 VS cmd prompt there was error during compilation. This was the reason why I installed Service Pack 1 for Visual Studio 2010 and used x64 cmd prompt instead (..assuming that x86 VS cmd prompt is not working on my x64 machine) Bad idea, it works. But without SP 1 there are errors during build of Qt 4.7.4

      • Posted December 14, 2011 at 11:11 am | #

        If I may, you probably should add a comment in the steps or just below about the fact that win32-msvc2010 is for both: 32 & 64 bit compiles.

  29. Florian
    Posted October 30, 2011 at 5:23 pm | #

    Thanks a lot! Works great!

  30. tonnot
    Posted November 9, 2011 at 2:46 am | #

    First Thanks for your help (I dont understand why there is not similar ‘official’ help on QT web page …. )
    I have two problems-questions….
    First: Have I to build a debug_and_release QT ? Now, I see how release and debug versions are created. (###.dll /lid and ###d.dll /lib )
    I’m a bit confused…. The ### files are ‘pure’ release versions and ###d. ‘pure’ debug versions ? What are the difference with a ‘debug_and_release’ build ?
    Second:
    On release mode I can compile my app but on debug mode I have a link error: cannot find QtOpenGLd4.dll.
    If I look at my /bin folder I see there is a #4.dll / #4.lib / #4d.dll /4d.lib for every qt library except QtOpenGLd4.dll. (I have only the release version ) What is happen ? Any idea ?
    Thanks .

  31. HenHen
    Posted November 9, 2011 at 7:10 pm | #

    Thanks alot, worked fine for me at last. Was trying to get qt running for VS10 for quite some time, but always gave up in between, because i was frustrated that it spit out, for me unresolvable errors during compilation of my files…
    Up to now i think this solution works :)
    For such a big project as QT the instructions give on their website are a joke, its too hard to get it running if you aren’t a experienced computer science guy.
    So thank again for this help!

  32. VelvetJ
    Posted November 13, 2011 at 9:13 pm | #

    I’m getting a bunch of errors during compilation “warning C4100: unreferenced global data”. So far, I’ve only noticed it during the section where its compiling javascript, but I haven’t been following it the read out closely, so it might have occurred during other parts as well.

    Do you know what might cause this issue? Also, since its still compiling, and most of it seems to be compiling correctly, do you know if might be a critical problem when I actually try to use the libraries?

    Thanks

    • Posted November 14, 2011 at 9:13 am | #

      It is not “error”, it is “warning”.
      C4100 is not critical (otherwise it would be reported as “error”), it just means there is global variable defined but not used.

  33. Posted November 18, 2011 at 10:19 am | #

    I would appreciate it if you put the description of the -j parameter inline with the instructions.

  34. John Howe
    Posted November 19, 2011 at 4:40 am | #

    I followed the directions to a “T” and having problems with the last stage of building. Everything compiled okay though but the build stopped.

    I have Win7 X64
    VS 2010 (Ultimate)

    Every time I run the,” ..\jom\jom.exe -j 5″, It stops in a different area. If I run it again, it will pass this error and have another manifest issue.

    I even tried to open the VC CMD window in Admin mode, didn’t help.

    link /LIBPATH:”d:\Qt\4.7.4\lib” /LIBPATH:”d:\Qt\4.7.4\lib” /NOLOGO /INCREMENTAL:
    NO /MANIFEST /MANIFESTFILE:”tmp\obj\release_shared\testcon.intermediate.manifest
    ” /SUBSYSTEM:WINDOWS “/MANIFESTDEPENDENCY:type=’win32′ name=’Microsoft.Windows.C
    ommon-Controls’ version=’6.0.0.0′ publicKeyToken=’6595b64144ccf1df’ language=’*’
    processorArchitecture=’*'” /OUT:release\testcon.exe @C:\Users\John\AppData\Loca
    l\Temp\testcon.exe.61547792.jom
    mt.exe -nologo -manifest “tmp\obj\release_shared\testcon.intermediate.manifest”
    -outputresource:release\testcon.exe;1

    mt.exe : general error c101008d: Failed to write the updated manifest to the res
    ource of file “release\testcon.exe”. Access is denied.
    command failed with exit code 31
    command failed with exit code 2
    command failed with exit code 2
    command failed with exit code 2
    command failed with exit code 2

    D:\Qt\4.7.4>

    Does anybody know why I seem to be having this problem? The whole compile process seems to have worked, just the manifest area.

    Thanks!
    John

    • Posted November 19, 2011 at 8:58 am | #

      Floating “c101008d” error is known problem of VC (not related to Qt) and was reported to MS few times (google for it).
      Unfortunately no solution is provided yet. All I can suggest is to install latest service pack for VC, try to turn off antivirus protection during compilation or try to compile Qt on another PC.

    • Evon
      Posted November 19, 2011 at 10:08 am | #

      Do you really have 5 cores? I’m taking a shot in the dark here, but that might affect your build if you only have a quad-core processor.

      • Evon
        Posted November 19, 2011 at 10:09 am | #

        I second Pavel’s suggestion to make sure you have SP1, btw. I was experiencing similar behavior until I updated my VS2010.

        • Anonymous
          Posted November 19, 2011 at 10:14 am | #

          I have a quad. Good rule to compile is N+1.

          I have installed SP-1.

          The issues I am having seem to be file permissions.

          • Posted November 19, 2011 at 2:16 pm | #

            If you build under “admin” then only antivirus (or other security software) could mess up access to files.

          • John Howe
            Posted November 19, 2011 at 2:23 pm | #

            I’m getting 4 updates for 2010. Hope this works.

            If this doesn’t work, then I may just get the pre-compiled binaries from Nokia and use VS2008.

            I just want to get QT working fast and build a sample project.

            Thanks for all the help.

            I will post anything eventful.

            Thanks,
            John

  35. John Howe
    Posted November 19, 2011 at 5:10 pm | #

    Figured it out. Thanks to the advice of turning off my anti-virus, it built fine.

    I searched other sites for same error code and most had to do with AV. Had to do with filenames or combinations of file name being create then copied; then AV would block read access for a short period of time and return “bad handle” back to caller.

    Thanks all, make sure to turn off AV no matter which one you have if goofy problems. To bad this is an issue… Only have to do this once in a while though and can disconnect from internet when building future bins.

    I have AVG and found other AV’s out there that are causing same issue. Apparently with some file names being created and copied too soon, AV’s pick up on this and block access.

    Thanks All,
    -John

  36. Ruben Javier
    Posted December 5, 2011 at 11:15 pm | #

    Hi, thank you very much for your guide, I have one question, If I already have a set of Qt libraries that I know where compiled with msvc, how can I know if they where compiled for x86 instead of x64?. Thanks in advance

  37. Andrei
    Posted December 7, 2011 at 10:11 am | #

    I have the following error:


    c:\QtSDK\Desktop\Qt\4.7.4\msvc2010\bin\idc.exe debug\comapp.exe /idl tmp
    \obj\debug_shared/comapp.idl -version 1.0

    tmp\obj\debug_shared\comapp.idl

    IDL generation failed trying to run program debug\comapp.exe!
    midl tmp\obj\debug_shared/comapp.idl /nologo /tlb tmp\obj\debug_shared/c
    omapp.tlb
    Processing tmp\obj\debug_shared\comapp.idl
    comapp.idl
    c1 : fatal error C1083: Cannot open source file: ‘tmp\obj\debug_shared\comapp.id
    l’: No such file or directory

    Any idea how to finish compiling?

    • Posted December 7, 2011 at 10:36 am | #

      Try to turn off antivirus software, which can block access to files.

      • Andrei
        Posted December 8, 2011 at 2:50 am | #

        I got the same error even with the antivirus being disabled. comapp.idl is not generated for some reason, I searched for it in the msvc2010 folder

        • Grega
          Posted December 9, 2011 at 12:10 am | #

          Hi Pavel!

          I have a very similar error as Andrei: “IDL generation failed trying to run program release\comapp.exe”
          So the debug part seems to be OK.
          I also disabled AV, but with no success. Do you have any idea what is wrong?

          I will try again with the network cable unplugged…

          • Grega
            Posted December 9, 2011 at 12:12 am | #

            I forgot to add:
            I got the following message (window) when it stopped compiling:
            “The procedure entry point ??0QVariant@@QAE@HPBXI@Z could not be located in the dynamic link library QtCore4.dll”

          • Grega
            Posted December 9, 2011 at 4:13 pm | #

            It has finished the compilation normally with nmake.

          • Posted December 9, 2011 at 4:48 pm | #

            Thank you Grega for information, I think latest jom might has a bug.

          • Posted December 15, 2011 at 8:18 am | #

            I had a similar problem while compiling examples. It told me that the ??0QVariant@@QAE@M@Z did not exist. Yet, looking inside the QtCore4.dll file, it exists. So I’m not too sure why it could not find it.

            Since that happened in the examples, everything else worked so I guess I have a working version of Qt now.

            Thank you for the instructions!
            Alexis

          • Posted December 19, 2011 at 10:08 am | #

            Okay! Got it!

            The computer is from work and they installed another tool that makes use of Qt 4.x as well. Problem is, that other tool is compiled and linked with an older version of Qt (4.5.2). So whenever a tool is loaded, it may instead load that other version because it was installed in a C:\windows\WOW64(something) folder which is automatically scanned by the operating system (in other words, changing your %PATH% variable has no effect.)

            In other words, my compile did work just fine, only that other version of Qt 64bit is in the way!

            Speaking of that, I also noticed that Perforce was making use of Qt. But at least they keep those libraries in their own personal bin folders.

            Thanks again for the info on this page!
            Alexis

          • Posted December 19, 2011 at 11:59 am | #

            Thanks Alexis for sharing your solution!

  38. Evon
    Posted December 20, 2011 at 1:56 am | #

    FYI, I just successfully compiled a 64bit version of 4.8.0 using msvc2010 SP1 on my Windows 7 x64 machine. It works with Qt Creator 2.3.1; I haven’t used the VS add-in (which Nokia no longer supports, btw). I used jom 1.06 for my compile again since people have been complaining about the latest version having bugs.

    • Posted December 20, 2011 at 10:40 am | #

      Thanks Evon, I’ve updated the post. They’ve released 4.8.0 on Qt Developer Conference in Tokyo, which I was lucky to attend :) .

    • tjach
      Posted December 27, 2011 at 2:13 am | #

      Well, I haven’t been so succesfull. Had to alter .pro file not to include examples and demos, which didn’t compile. Qt 4.8, win 7 x64.
      Apart from that, the VS addon still works – but is unable to invoke qt designer.
      Previously created projects compile fine.

  39. Heng
    Posted January 17, 2012 at 3:58 am | #

    Hi, I have got a problem when I compile 64bit Qt 4.8.0 in VS2010, windows 7 (x64).
    I followed the step you provide.
    1, I download 4.8.0 using the link you give, and put it in E:\Qt\4.8.0
    2, Environment varible and path were set correctly.
    3, jom106 is downloaded into e:\Qt\jom
    4, in Visual Studio x64 Win64 Command Prompt (2010), I change the dir to E:\Qt\4.8.0
    configure -debug-and-release -opensource -platform win32-msvc2010
    ..\jom\jom.exe -j 8

    after compilation, it says

    command failed with exit code 2
    command failed with exit code 2
    command failed with exit code 2
    command failed with exit code 2

    And the file’s size now is only 4GB+, not 7GB.
    what is this problem?

    Thanks in advance.

    Heng

    • Posted February 1, 2012 at 9:23 am | #

      Try to: (1) turn off your antivirus; (2) install SP1 for visual studio if you’ve not done it yet.

  40. Boba
    Posted February 14, 2012 at 5:49 pm | #

    Hi folks,

    I got the following error while trying to compile Qt 4.7.1:

    IDL generation failed trying to run program release\openglax.exe!
    midl tmp\obj\release_shared/openglax.idl /nologo /tlb tmp\obj\release_sh
    ared/openglax.tlb
    Processing tmp\obj\release_shared\openglax.idl
    openglax.idl
    c1 : fatal error C1083: Cannot open source file: ‘tmp\obj\release_shared\opengla
    x.idl’: No such file or directory
    midl : command line error MIDL1003 : error returned by the C preprocessor (2)
    jom: C:\Qt\4.7.1\examples\activeqt\opengl\Makefile.Release [release\openglax.exe
    ] Error 1003
    jom: C:\Qt\4.7.1\examples\activeqt\opengl\Makefile [release-all] Error 2
    jom: C:\Qt\4.7.1\examples\activeqt\Makefile [sub-opengl-make_default] Error 2
    jom: C:\Qt\4.7.1\examples\Makefile [sub-activeqt-make_default] Error 2
    jom: C:\Qt\4.7.1\Makefile [sub-examples-make_default-ordered] Error 2

    I did try to compile using ..\jom\jom.exe -j 2 on a computer with the following configuration: Intel(R) Core(TM)2 Duo CPU E(%== @ 3.16 GHz 3.16 GHz

    Thank you for your help in advance,

    Boba

    • Posted February 15, 2012 at 9:18 am | #

      It seems like something wrong with file access rights – similar problems happened before. Try to turn off your antivirus.

  41. Bisoo
    Posted February 16, 2012 at 9:23 am | #

    Hi, will this tutorial work for Visual C++ 2010 Express? I want to be able to use the IDE for Qt development. I can’t seem to find any free version of Visual Studio 2010. Please respond and thanks in advance.

    • Posted February 16, 2012 at 5:08 pm | #

      Qt Visual Studio Add-in won’t work with VC 2010 express. Without this add-in it will be very difficult to develop Qt applications using VC. Your best bet is Qt Creator.

  42. Alex
    Posted February 26, 2012 at 7:31 pm | #

    Makefile not found when trying to jom -j 2?.Where to get it? Please help, 4.8.0

    • Posted February 27, 2012 at 2:13 pm | #

      Did you run configure before jom?

      • Alex
        Posted February 27, 2012 at 7:02 pm | #

        Yes, run configure -debug-and-release -opensource -platform win32-msvc2010, jom is last version 1010 or so on, copied to 4.8.0\jom and to c:\Qt\jom. Tried nmake also. короче ничего не помогло.

        • Ag
          Posted March 16, 2012 at 4:21 pm | #

          I have same problem.
          I write “qmake” after configuration and it fix jom makefile error
          Iam not sure that it is right but it works

  43. Snouty
    Posted April 5, 2012 at 2:14 am | #

    Thanks a lot for this tutorial. I just successfully compiled a 32bit version of 4.8.1 (Visual Studio 10 Ultimate, Win 7, i5). Took me round about 4 hours, but everything works now :)

  44. LP
    Posted April 7, 2012 at 9:40 am | #

    If everyone gets “no makefile” error when running jom, you probably don’t have Perl and so it cannot run the configuration correctly, I’m not quite sure if this is the solution, but go to the QT directory\bin\ and delete the syncqt.bat.
    After that run the configure …. again. Then now jom should work.

  45. Posted April 17, 2012 at 8:35 pm | #

    I used these instructions to compile QT 4.8.1 in both 32 and 64 bit on Windows 7. Both versions compiled without problems in about 45 minutes each using an i7 chip and all 8 virtual cores. The only hitch was that I had to install Perl first; I used ActiveState Perl from here http://www.perl.org/get.html and it worked with all the default settings.

    Thank you for these instructions!! I’ve looked at a dozen other “tutorials” and I failed with them. This is so clear and easy to follow. It saves many hours of headaches.

  46. Posted April 26, 2012 at 11:10 am | #

    Hey thanks for this awesome tut! Tried many others and they caused headaches and many upon many wasted hours.
    Used it for building 4.8.1 libraries with msvc2010 in x86 vs cmd. Works perfect.
    Thanks again, you have saved many people lots of time.

    All the best

Post a Comment

Your email is never published nor shared.

Use native LaTeX syntax to include formulas: $ ... $, \[ ... \], etc. Do not forget to preview comment before posting.

Also you may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting