Building Qt 5.9.1 on Windows 7/10 with Visual Studio 2017

2017-08-18

Time again for an follow-up to my post on Qt’s LTS release, now that Qt 5.9 has been published as a new long-term supported (LTS) release.

And since Qt 5.9.1 does not build with Visual Studio 2010 anylonger, this was also a good reason to switch to the freshly released Visual Studio 2017 Community Edition.

What has not changed is my reliance on Windows 7 on my main box (an upgrade is maybe due this fall or winter…); but I had also the chance to run these following steps on a Windows 10 machine (with ‘Creators Update’).

By running a current compiler now, there is not necessarily a reason for this article: a pre-compiled package of Qt for Visual Studio 2017 is available AFAIK — but I somehow got accustomed to building my own little Qt, so I’ll stick with it for now. (It’s also a good reason for practice and in this case finally triggered my switch to a newer version of Visual Studio.)

Prerequisites and recommended installation order

  1. Microsoft Visual Studio 2017 (Community Edition)
  2. … install it with the C++ Desktop workload, the C++ toolset and the Windows SDK (VS2017 is brandnew to me, this might get more detailed in future updates.)
  3. Perl
  4. Python

Tools like Perl should be in PATH for the command prompt build environment.

Getting and building Qt

  1. The download of the plain source code for older/not-mainstream versions is well hidden on the Qt site. On the Open-Source-Download page, under section 2, there’s “Source packages & Other releases”, where you can get the source code of 5.9.1 for Windows as a *.zip file: http://download.qt.io/official_releases/qt/5.9/5.9.1/single/qt-everywhere-opensource-src-5.9.1.zip

  2. Extract it to an appropriate place, e.g. C:\devel\ext\Qt\5.9.1\. If your extraction tool of choice puts it into sub-directories like qt-everywhere-opensource-src-5.9.1 then move the content of it up to the root level and delete this now empty folder(s).

  3. Build 64-bit DLLs with Visual Studio 2010 (for 32-bit files, adjust paths, names, and options accordingly):

    1. Open the x64 Native Tools Command Prompt for VS 2017 from the start menu (Visual Studio 2017 → Visual Studio Tools → VC) and navigate to C:\devel\ext\Qt\5.9.1\

    2. Run Qt’s configure.bat to set up the build, for example with these parameter values (note that this is a setup that works for me, but I use Qt currently only for certain projects with specific needs; you may need different features enabled/disabled, etc.):

      Argument Comment
      -confirm-license To get rid of the question whether you agree to the license.
      -prefix DIRECTORY Target directory, e.g. a full path like C:\devel\ext\Qt\5.9.1\_64DLL
      -release
      -opensource
      -shared Creatings DLLs instead of static libraries.
      -platform win32-msvc2017 Use Microsoft Visual C++ 2017.
      -mp Use multiple processors for compiling with Microsoft Visual C++ (-MP).
      -make tools For lupdate/linguist/lrelease and so on.
      -nomake examples Because examples (esp. OpenGL ones) messed up the build.
      -nomake tests
      -no-icu Library for Unicode and Globalization support. This would be required for building Qt WebKit.
      But Qt also supports Unicode by default and ICU seems to be on the way out for Qt’s future…
      -no-opengl
      -no-angle ANGLE would translate OpenGL calls into DirectX calls.
      -no-openssl
    3. Type nmake to kick-off the building process; this will take quite a while… If you get at the very end get some minor errors from the tools (not able to ‘cd’ etc.), but not failure of the build itself, just ignore it.

      To clean up configure (after a failed build), use nmake distclean.

    4. Type nmake install to move the built binaries to the target directory. (Again: If you get at the very end get some minor errors from the tools (not able to ‘cd’ etc.), just ignore it.)

That’s it!

6 comments on “Building Qt 5.9.1 on Windows 7/10 with Visual Studio 2017

  1. Peter

    Are these minor errors you mentioned?

    R:\Dev\Qt\qt5\qtbase\src\corelib\tools\qcollator_win.cpp(45): fatal error C1083: Cannot open include file: ‘QDebug’: No such file or directory
    qcommandlineoption.cpp
    qcommandlineparser.cpp
    qharfbuzz.cpp
    NMAKE : fatal error U1077: ‘”R:\Dev\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.EXE”‘ : return code ‘0x2’
    Stop.
    NMAKE : fatal error U1077: ‘”R:\Dev\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe”‘ : return code ‘0x2’
    Stop.
    NMAKE : fatal error U1077: ‘cd’ : return code ‘0x2’
    Stop.
    NMAKE : fatal error U1077: ‘cd’ : return code ‘0x2’
    Stop.
    NMAKE : fatal error U1077: ‘cd’ : return code ‘0x2’
    Stop.

  2. Sascha Offe Post author

    Yes, I mean the fatal error U1077 (‘cd’: return code ‘0x2’). Seems to be a problem with some very long paths, but the build still succeeds and for now, I haven’t notice any issues with the resulting binaries, so I ignore it 😉

    (I don’t remember coming accross the other one you metioned in your comment, fatal error C1083.)

  3. Tim

    C1083 is not so minor – it happens at the very beginning and nothing except QtCore is built as a result 🙁

  4. Sascha Offe Post author

    > C1083 is not so minor – it happens at the very beginning and nothing except QtCore is built as a result

    As I mentioned in my other comment, I haven’t come accross that particular error myself when I built Qt, so I can’t say what may cause that.

    The first match for that error tells something about being not able to find some files. Strange, for such a heavily tested and used framework… maybe that is a red herring of a message and one has to dig deeper for the real trigger.

    But as said: Didn’t happen to me yet, so I can’t help.
    (My applications use usually at least Qt5Core, Qt5GUI and Qt5Widgets, and I didn’t yet have any problems when building those programs with my “home-made” Qt libraries.)

  5. Chris

    I’ve had the same problem with QDebug. The reason was that I was using a MINGW64 perl version that was in my %PATH% (through git or some other tool). The problem went away after putting the path to strawberry-perl before the other entries in %PATH%.

  6. Pingback: Building QT 5.10.1 with VS2017 | DeveloperNote.com

Leave a comment

Your email address will not be published.