Saturday, 5 May 2018

Building QT Windows Apps

Introduction

Note: This blog entry covers version 5.10.1 and 5.12.3 of QT.

QT has many different options for building Windows applications.  This note presents four of them, all using freely available software.

These options are:
  • MinGW32
    • advantages: Don't need to distribute the MSVC runtime, and the debugger is available and already configured.
  • MinGW64
    • advantages: Don't need to distribute the MSVC runtime, and the debugger is available and already configured. and Can handle programs which have large memory usage.
    • MSVC2015/7 32 bit
      • advantages: Runs on 32-bit platforms, and has better accessibility support than MinGW32.
    • MSVC2015/7 64 bit
      • advantages: Can handle programs which have large memory usage, and has better accessibility support than MinGW64.

    QT5.10.1 MSVC2015: Install QT:

    QT 5.10.1 is not an option in the unified installer, so the specific package must be downloaded.
    Also, the installer framework is not bundled with the package, so if the installer in 5.12.3 is not going to be used, it must be downloaded and installed separately.

    Download QT 5.10.1 from:  https://download.qt.io/official_releases/qt/5.10/5.10.1/
    Download QT Installer Framework 3.0 from: https://download.qt.io/official_releases/qt-installer-framework/3.1.0/

    Run the qt-opensource-windows-x86-5.10.1 installer, and:
    • Select QT 5.10.1 - Targetting msvc2015 32 & 64-bit if desired
    • Select QT 5.10.1 - Targetting MinGW 5.3.0 if desired
    • Select MinGW Libraries 5.3.0 if desired
    • Select WebEngine Libraries
    • Install into X:\QT5.10.1
    Run the QtInstallerFramework-3.1.0-win-x86, and:
    • Install into X:\QTIFW3.1.0

    QT5.12.3 MSVC2017: Install QT:

    Download QT From:  https://www1.qt.io/download-open-source

    Run the qt-unified-windows-installer, and:
    • Select QT 5.12.3- Targetting msvc2017 32 & 64-bit if desired
    • Select QT 5.12.3 - Targetting MinGW 7.3.0 32 & 64-bit if desired
    • Select Installer 3.0
    • Select MinGW Libraries 7.3.0 if desired
    • Select WebEngine Libraries
    • Install into X:\QT
    Install SSL (optional):

    May not be required, at least for MinGW installations, due to files being found in the Qt tree.

    Download OpenSSL From: https://slproweb.com/products/win32openSSL.html

    Run the installer, and:
    • Install into X:\OpenSSL-Win32
    • or X:\OpenSSL-Win64

    Install Git (optional):

    Download Git from: https://git-scm.com/download/win

    Run the "Git-x-xx-x" installer and:

    • Select Large File Support
    • Associate .sh to be run with Bash
    • Use Git from Bash Prompt Only
    • Use OpenSSL
    • Checkout as-is, Commit Unix-style
    • Use MinTTY
    • Explorer integration is not necessary
    • Install into X:\Git
    • Add X:\Git\bin to the path

    Install DotNet Framework Developer Pack:

    This is only required if MSVC is to be used, and the currently installed version of .Net is below 4.5.1.

    Download DotNet from: https://www.microsoft.com/net/download/windows

    Run the nd48-devpack-enu.exe installer and:

    • Install into default location (C:)

    Install ICU (optional):

    Has  been found to be necessary for Webkit applications.

    Download ICU Binary for Windows (VS2015) from: http://site.icu-project.org/download
    It is not clear if later versions than 60.2 support MSVC2015.

    Run the installer and:
    • Instal into X:\ICU 


    QT5.10.1 MSVC2015: Install Microsoft Visual C++ (VC14) Build Tools 2015:

    Uninstall previous build tools 2015 / VC14, and the 2015/VC14 runtime.

    Download "Visual C++ Build Tools 2015 Update 3" from: https://www.visualstudio.com/vs/older-downloads/

    Download "Microsoft Build Tools 2015 Update 3" from https://www.visualstudio.com/vs/older-downloads/

    Run the "visualcppbuildtools_full.exe" installer and:
    • Select custom install
    • Select the Windows 8.1 SDK only if your code contains #include <windows.h>
    • Otherwise, don't select any SDKs or Options
    • Install into default location (C:)
    Download "Microsoft Visual C++ 2015 Redistributable Update 3" runtime from https://www.visualstudio.com/vs/older-downloads/
    • Keep a copy of "vc_redist.x64.exe" to include in your distribution.
    • Run the program and install into the default location (C:)

    QT5.12.3 MSVC2017: Install Microsoft Visual C++ (VC15) Build Tools 2017:

    Uninstall previous build tools 2017 / VC15, and the 2017/VC15 runtime.

    Download "Build Tools for Visual Studio 2017 (version 15.0)" from: https://www.visualstudio.com/vs/older-downloads/
    Run the "vs_buildtools.exe" installer and:
    • Select the  "Individual Components" tab
    • Update if necessary, then ensure the following are selected:
      • Static analysis tools *1
      • Clang/C2 *1
      • VC++ 2015.3 v14.00 *1
      • VC++ 2017 Version 15.9 v14.16
      • VisualC++ 2017 Redistributable Update
      • Visual C++ tools for CMake
      • Windows Universal CRT SDK *2
      • Testing tools core features - Build Tools
      • Visual C++ Build tools core features
      • Visual Studio C++ core features
      • Windows 10 SDK *2
      • Windows 8.1 SDK *2
      • Windows Universal C Runtime
    • Install into the default location (C:)
    *1 - May not be necessary
    *2 - Only required if you have #include <windows.h>

    Deployment:

    Build your application, and then transfer the .exe file to your distribution folder.
    At the command prompt, run 'windeployqt filename.exe' and all of the required Qt DLLs and support files will be transferred.

    You will also need to transfer additional files, depending on which library or features you are using.  These will come from distributions such as MinGW, Microsoft Runtime, OpenSSL and ICU.

    You can use the depends.exe dependency walker, which is bundled with numerous Microsoft development tools, and is also available from www.dependencywalker.com. Note that this tool does not detect DLLs which are opened with the dlopen method, as these are dynamically loaded.

    Example MinGW 32-bit Libraries

    These libraries can be found in the QT\Tools\mingw530_32\bin folder:
    • libgcc_s_dw2-1.dll
    • libstdc++-6.dll
    • libwinpthread-1.dll

    Example OpenSSL Libraries

    If you don't have any SSL networking code, you don't need these libraries.

    These libraries are loaded with the dlopen method, and as such, will not be detected with the dependency walker.  They are also not installed with the windeployqt application - all of this is due to export licensing restrictions.

    The symptom of a missing OpenSSL library looks like a network failure when trying to connect to an SSL server (e.g. https).

    There are several different versions of these libraries (in the Qt distribution and the Git distribution), but the following has been found to work OK: QT\Tools\mingw530_32\opt\bin:
    • libeay32.dll
    • ssleay32.dll

    References

    https://github.com/alamminsalo/orion/wiki/Windows-MSVC-dev-setup