Building QT with Visual Studio 2015 - Guide lines



  • I had an installation in c:\Qt\Qt5.4.1 compiled with VS2013 (jom and winflex installed) but needed the new C++11 features in Visual Studio 2015. I guess you can follow this guide with a fresh QT installation of higher versions too, but I have not tested that. The basic trick is to alter one file so the VS2015 compiler is choosen instead of VS2013, but we're keeping all "names" like msvc2013 "everywhere". Below are the steps I did with some comments:

    1. This step just necessary if you want to keep your previous installation:
      Copy c:\Qt\Qt5.4.1 to create backup c:\Qt\Qt5.4.1_for_VisualStudio2013

    2. In file c:\Qt\Qt5.4.1\5.4\Src\qtbase\mkspecs\win32-msvc2013\qmake.conf change:

      a)
      MSVC_VER = 12.0
      to
      MSVC_VER = 14.0

      b)
      QMAKE_COMPILER_DEFINES += _MSC_VER=1800 _WIN32
      to
      QMAKE_COMPILER_DEFINES += _MSC_VER=1900 _WIN32

      If you start your compiler with "cl /?", you will see a number starting with 19.00 which give you 1900 above. Number 14 is the VS2015 compiler version. (Why it's not 15.0 and previous 12.0 is not 13.0 is a mystery ...)

    3. Open a command window. (cmd.exe)

      Set the environment to VS2015 and pathes to jom and winflex. Notice that you have to change pathes suited for your installations of VS2015 etc:

      set PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin;%PATH%
      CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
      set PATH=c:\Qt\Qt5.4.1\5.4\winflex;c:\Qt\Qt5.4.1\5.4\jom;c:\Qt\Qt5.4.1\5.4\Src\qtbase;%PATH%
      set QMAKESPEC=win32-msvc2013

      Note that we changed the settings in file c:\Qt\Qt5.4.1\5.4\Src\qtbase\mkspecs\win32-msvc2013\qmake.conf,
      so "set QMAKESPEC=win32-msvc2013" is actually right!

    1. In the command window:

      cd c:\Qt\Qt5.4.1\5.4\Src\qtbase

    1. This step is crucial if you started from a previous compiled Qt installation as I did. All configurations must be erased otherwise you end up with precompiled headers from your previous Visual Studio and wont be able to build. In the command window from step 3) run:

      nmake confclean

    2. Now it is time to configure and this is how I configured. Alter the options you want and execute configure in the command window you opened in step 3).

      configure -opengl desktop -no-icu -c++11 -commercial -debug-and-release -qt-sql-sqlite -D "_BIND_TO_CURRENT_CRT_VERSION=1" -mp

    3. Build with "nmake" in the command window you opened in step 3).

    4. Note that Visual Studio 2015 does not support addins any longer, so the QtAddin cannot be used. Maybe there is a work around for this?

    Alternativ soultion
    I've also tried another approach were folder c:\Qt\Qt5.4.1\5.4\Src\qtbase\mkspecs\win32-msvc2013 is copied to c:\Qt\Qt5.4.1\5.4\Src\qtbase\mkspecs\win32-msvc2015 and changed as in step 2) above. Then when you want to configure, you realize that c:\Qt\Qt5.4.1\5.4\Src\qtbase\configure.exe has hard coded "msvc2013". So running configure won't work, unless you change "msvc2013" to "msvc2015" in 3 places in that binary. You can perform that change with a binary editor like HexEdit from htpp:/www.hexedit.com . After this your configure.exe program can configure for Vs2015. Note that you're stuck with your previous makefiles from VS2013 everywhere, so this solution is best suited for rebuilding only the qtbase if I understood it correctly. For example, if you're going to rebuild the qtbase you have to change in file c:\Qt\Qt5.4.1\5.4\Src\qtbase\qmake\Makefile.win32 and
    add || "$(QMAKESPEC)" == "win32-msvc2015" in 2 if statements.

    I hope this can help some people out there.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.