[SOLVED] Problems building 5.1.0 using MSVC 2012 targeting Windows XP

  • I'm on Windows 7 x64 and I'm attempting to build Qt 5.1.0 using MSVC 2012 (Update 3). I'm trying to target Windows XP x86, however I can't even get configure.bat to exit without errors.

    First the output is littered with warnings like this:

    @c:\program files (x86)\microsoft sdks\windows\v7.1a\include\sal_supp.h(57) : warning C4005: '__useHeader' : macro redefinition (C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\qmake\library\ioutils.cpp)
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\sal.h(2872) : see previous definition of '__useHeader'
    c:\program files (x86)\microsoft sdks\windows\v7.1a\include\specstrings_supp.h(77) : warning C4005: '__on_failure' : macro redefinition (C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\qmake\library\ioutils.cpp)
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\sal.h(2882) : see previous definition of '__on_failure'@

    Then the errors that kill it are:

    @C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\src\corelib\io\qfilesystemengine_win.cpp(612) : error C2065: 'FILE_ID_INFO' : undeclared identifier
    C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\src\corelib\io\qfilesystemengine_win.cpp(612) : error C2146: syntax error : missing ';' before identifier 'infoEx'
    C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\src\corelib\io\qfilesystemengine_win.cpp(612) : error C2065: 'infoEx' : undeclared identifier
    C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\src\corelib\io\qfilesystemengine_win.cpp(614) : error C2065: 'infoEx' : undeclared identifier
    C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\src\corelib\io\qfilesystemengine_win.cpp(614) : error C2065: 'FILE_ID_INFO' : undeclared identifier
    C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\src\corelib\io\qfilesystemengine_win.cpp(614) : error C2070: ''unknown-type'': illegal sizeof operand
    C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\src\corelib\io\qfilesystemengine_win.cpp(615) : error C2065: 'infoEx' : undeclared identifier
    C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\src\corelib\io\qfilesystemengine_win.cpp(615) : error C2228: left of '.VolumeSerialNumber' must have class/struct/union
    type is ''unknown-type''

    It looks like a conflict between the Windows 8 Kit and the Windows 7 SDK, the latter being required for targeting Windows XP using msvc2012. The steps needed to build for XP using msvc2012 are "outlined here":http://blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx.

    I've followed those steps, however looking at the compilation commands from configure's output it seems as though the compiler define


    is not being used at all, despite my specifying it. The steps I'm using to build are as follows:

    Start a command prompt that sets up the environment variables:

    @set QT_SOURCE=C:\qt\5.1.0\5.1.0-windowsxp-x86-shared
    call "%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86
    set PATH=%QT_SOURCE%\qtbase\bin;%QT_SOURCE%\qtrepotools\bin;%QT_SOURCE%\gnuwin32\bin;%PATH%
    set QMAKESPEC=win32-msvc2012

    set INCLUDE=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Include;%INCLUDE%
    set PATH=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Bin;%PATH%
    set LIB=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Lib;%LIB%
    set CL=/D_USING_V110_SDK71_;%CL%@

    I modified two lines in the makespec file


    as follows, to match the instructions at the link above:


    Then used the following configure command from the top of the source tree (not from qtbase/):

    @configure.bat -debug-and-release -opensource -confirm-license -c++11 -shared -ltcg -skip qtmultimedia -skip qtwebkit -skip qtwebkit-examples -skip qtquick1 -skip qtquickcontrols -skip qtjsbackend -skip qtdeclarative -nomake tests -no-icu -no-opengl -no-angle -no-audio-backend -no-qml-debug -plugin-sql-sqlite -I C:\OpenSSL-Win32\include -L C:\OpenSSL-Win32\lib -openssl -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -mp@

    Here is an example compiler call from configure's output:

    @Creating qmake...
    cl -c -Fo./ -W3 -nologo -O1 /MP -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\qmake -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\qmake\library -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\qmake\generators -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\qmake\generators\unix -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\qmake\generators\win32 -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\qmake\generators\mac -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\qmake\generators\integrity -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\include -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\include\QtCore -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\include\QtCore\5.1.0 -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\include\QtCore\5.1.0\QtCore -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\src\corelib\global -DHAVE_QCONFIG_CPP -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\mkspecs\win32-msvc2012 -IC:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\tools\shared -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED -DPROEVALUATOR_FULL -DPROEVALUATOR_DEBUG -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_COMPRESS -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM -DUNICODE -c -Yc -Fpqmake_pch.pch -TP C:\qt\5.1.0\5.1.0-windowsxp-x86-shared\qtbase\qmake\qmake_pch.h@

    No mention of the define


    Why not? I tried specifying it both in the CL environment variable and in the configure command (using -D), neither method worked.

    Qt builds fine if I don't target XP. How do I overcome these errors?

  • UPDATE: Okay, so it's now a few hours later Qt 5.1.0 is built successfully, targeting Windows XP. I'm yet to actually test it on an XP machine, I'll do that later today or tomorrow when I get a chance. Here are the steps I had to take to get this working:

    Modify the file


    by adding a third OR component to the conditional on line 574:

    @# if defined(Q_CC_MINGW) || (defined(Q_CC_MSVC) && _MSC_VER < 1700) || (defined(Q_CC_MSVC) && _MSC_VER >= 1700 && defined(USING_V110_SDK71))@

    The reason for doing this is that qmake fails to build because the type FILE_ID_INFO is undeclared and the declaration is inside that ifdef. When using msvc2012 _MSC_VER is >= 1700, so the declaration is skipped. Also in the system header winbase.h, FILE_ID_INFO is declared for OS version >= Windows 8, so in my case on Windows 7 it is skipped there as well. The above change fixes that.

    Modify the file


    by adding the SDK7 macro to the CFLAGS_BARE variable so qmake will build without all the redefinition warnings:

    @CFLAGS_BARE = -c -Fo./

    And a similar change with the next file that affects the rest of the build apart from qmake. Modify the file


    add the SDK7 macro to the QMAKE_CFLAGS variable:

    @QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t -D_USING_V110_SDK71_@

    Also in the same file as per the first post, add the version number to the /SUBSYSTEM linker flag:


    Use the command prompt environment I posted in the first post to build from (the CL variable can probably be omitted since it doesn't seem to get picked up and I've just put the macro in the files manually).

    I had to add -nomake examples to my configure options (the rest is the same as in the first post) so that the OpenGL examples wouldn't kill the build. It would be nice if the configuration tool was smart enough to not try and build them if you specify -no-opengl. Strangely though most of the other examples do seem to have been built.

    That's it, the build worked for me after making those changes, I just need to test on XP.

    UPDATE: I've now tested one of the examples (widgets/richtext/textedit) on an XP virtual machine and it works fine. I had to add the following to the .pro file for building:

    @win32 {
    LIBS *= -L"%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Lib"
    INCLUDEPATH += "%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Include"

  • Moderators

    Great work; thank you for sharing your methods and results!

  • Thanks for these information.
    4.8.5 works as well.
    Setting CL/LINK on the command line is not required.
    Also I don't have to add the additional LIBS/INCLUDEPATH in the project.

    I didn't test it with x64, but keep in mind that LINK must be changed to /SUBSYSTEM:CONSOLE,5.02 (instead of ...5.01) "Reference":http://blogs.msdn.com/b/vcblog/archive/2012/10/08/windows-xp-targeting-with-c-in-visual-studio-2012.aspx

Log in to reply

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