Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile Qt for 64-bit Windows from a 32-bit environment with Visual C++ 2010 Express?

I am trying to compile the Qt library (I don't need the demos or examples) for 64-bit Windows. There are instructions here but I run into the error described in the comment below it. There doesn't seem to be a reference anywhere for how one might go about doing this process.

I am targetting Microsoft Visual C++ 2010 Express. It looks like I need Perl and the Windows SDK as well - how do I go about this process?

like image 376
Nathan Osman Avatar asked Mar 03 '12 05:03

Nathan Osman


2 Answers

This process is quite tedious and time-consuming - but I will explain each step in detail here for the benefit of others who try to compile Qt in the future.

  1. The first step is to install all of the prerequisites.

    • ActivePerl, which is used during the configuration process. You will need to restart after installing Perl since it modifies environment variables.
    • The Windows SDK 7.1 (formerly called the Platform SDK). Be sure to include the x64 libraries when you select the components to install.

  2. Download the Qt source archive from the Qt Downloads page.

  3. Extract the contents of the archive to an easy-to-remember location (like C:\). You need to remember this location later since we will be using it to set some environment variables.

  4. Now open the Windows SDK 7.1 Command Prompt. Begin by setting the environment to 32-bit release mode (we need to build some of the tools as 32-bit applications):

    setenv /release /x86
    
  5. Set the following environment variables (example below assumes you extracted to C:\):

    set QTDIR=C:\qt-everywhere-opensource-src-4.8.0
    set PATH=%PATH%;%QTDIR%\bin
    
  6. Now run cd %QTDIR% and specify the configuration options - example is included below:

    configure -release -opensource -qt-zlib -qt-libpng -qt-libmng -qt-libtiff
     -qt-libjpeg -qt-style-windowsxp -qt-style-windowsvista -platform
     win32-msvc2010
    
  7. Once the configuration process is complete, cd to the src directory and run:

    qmake
    nmake
    

    This process may take a considerable amount of time, so now would be a good time to take a break and answer some questions here on Stack Overflow :)

  8. The tools are now built and you need to compile Qt as a 64-bit library. Enter the following command:

    setenv /x64
    

    You will need to set the environment variables from step 5 again. Enter those commands now.

  9. Run cd %QTDIR% and then rerun the configure command being sure to specify one additional option:

    configure -release -opensource -qt-zlib -qt-libpng -qt-libmng -qt-libtiff
     -qt-libjpeg -qt-style-windowsxp -qt-style-windowsvista -platform
     win32-msvc2010 -no-qmake
    

    The -no-qmake option is very important - it indicates that we want to skip the compilation of the qmake.exe program because we want to keep the 32-bit version.

  10. Now things get really complicated here because of some dependency problems. The tools (like moc) that Qt needs to build the core library and some of the other components are listed as dependencies in the src.pro file. This means that the compiler will attempt to build them as 64-bit applications and then try to run them - which will of course fail on a 32-bit system. So what we need to do is edit src.pro and remove those dependencies ourselves. Scroll down near line 85 and look for a line that begins with:

    !wince*:!ordered:!symbian-abld:!symbian-sbsv2 {
    

    Each subsequent line in the section lists a sub-target and its dependencies. What you want to do now is remove all dependencies that begin with src_tools_. For example:

    src_gui.depends = src_corelib src_tools_uic
    

    Becomes:

    src_gui.depends = src_corelib
    

    There might be a better way of doing this, but I haven't figured it out yet :)

  11. Now we cd into the src directory once again and run the following command

    nmake sub-winmain sub-corelib sub-xml sub-network sub-sql sub-testlib
     sub-gui sub-qt3support sub-activeqt sub-opengl sub-xmlpatterns sub-phonon
     sub-multimedia sub-svg sub-script sub-declarative sub-webkit
     sub-scripttools sub-plugins sub-imports
    

    This builds only the Qt libraries and skips the tool dependencies. Note that this too may take a considerable amount of time.

  12. You should now have 64-bit libraries in the lib folder that you can link against in your 64-bit Qt applications.


Edit: it turns out that even this wasn't enough since I still ran into some problems when linking the QtWebKit4.dll library (something about unresolved symbols). It turns out that someone else has already found the solution and you need to change QMAKE_HOST.arch to QMAKE_TARGET.arch in WebCore.pro.

Also, the above options will build QNetwork4.dll without OpenSSL support (you won't be able to access sites over HTTPS - even in a QWebView). This, thankfully isn't too hard to fix. Download and build OpenSSL for Win64 and append the options below to the command in step #9:

-openssl -I C:\OpenSSL\inc32 -L C:\OpenSSL\out32dll

(You'll have to change the paths if you installed OpenSSL somewhere other than C:\OpenSSL.)


Further edit: to save the trouble of doing this yourself, I have uploaded the compiled libraries here:
http://www.box.com/s/9710cbb278ef4890a7b5

like image 118
Nathan Osman Avatar answered Nov 17 '22 07:11

Nathan Osman


As I mentioned in the comments to George Edison's answer, there is a bug in the Microsoft Visual C++ compiler that comes with the Windows SDK 7.1. For more information on this, see QTBUG-11445 and QTBUG-19175.

I have compiled the Qt 4.8.2 64-bit binaries following George's instructions, including the OpenSSH library. In addition, I applied Microsoft's hotfix to fix the compiler bug.

For your convenience, I have made the resulting 64-bit libraries available for download from here: https://www.box.com/s/8948c60c3cdd743ef83b

like image 32
yori Avatar answered Nov 17 '22 05:11

yori