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

Time again for a follow-up to my post on building Qt’s recent LTS release with Visual Studio, 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.

  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 2017 (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.

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

    5. 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!