Windows XP Targeting with C++ in Visual Studio 2012

Windows XP Targeting with C++ in Visual Studio 2012

Rate This
  • Comments 42

Background

In June, we announced enhanced targeting for Windows XP using the Visual Studio 2012 C++ compiler and libraries. This feature has been included in Visual Studio 2012 Update 1. You can download it from here. The purpose of this article is to provide an overview of the Windows XP targeting experience, the level of C++ runtime support, and noteworthy differences from the default experience shipped in Visual Studio 2012 at RTM.

Windows XP Targeting Experience

In order to target Windows XP, switch from the default v110 toolset to the newly introduced v110_xp toolset inside your project’s property pages. This new platform toolset points to a repackaged version of the Windows 7 SDK shipped in Visual Studio 2010 instead of the Windows 8 SDK, but uses the same Visual Studio 2012 compiler. The v110_xp toolset also sets useful defaults such as a compatible linker subsystem version for downlevel targeting. Only executables built with this platform toolset are supported to run on Windows XP, but those same executables will also run on Vista, Windows 7 and Windows 8. 

C++ Runtime Support

The static and dynamic link libraries for the CRT, ConCRT/PPL, STL, and MFC have been updated in-place to add runtime support for Windows XP and Windows Server 2003. Applications written in C++/CLI which target the .NET Framework 4.0 will also run on Windows XP and Windows Server 2003. For these operating systems, the supported versions are Windows XP SP3 for x86, Windows XP SP2 for x64, and Windows Server 2003 SP2 for both x86 and x64.

Library

v110 (Vista+)

v110 (Store Apps)

v110_xp (XP/2k3+)

CRT

X

X

X

ConCRT/PPL

X

X

X

STL

X

X

X

MFC

X

 

X

ATL

X

X

X

C++ AMP

X

X

 

Differences from Vista+ Targeting

  1. Building HLSL
    Building HLSL with the v110_xp toolset is not enabled by default. To enable HLSL compilation, download the DirectX SDK (June 2010) and set your project’s VC directories manually to point to this SDK, in a similar manner as Visual Studio 2010. For more information, see the “DirectX SDK Does Not Register Include/Library Paths with Visual Studio 2010” section of the DirectX SDK (June 2010) download page.
     
  2. Debugging DirectX
    The Visual Studio 2012 Graphics Debugging experience is not supported when targeting DirectX 9.
     
  3. Static Analysis
    When selecting the v110_xp platform toolset, the static analysis experience is disabled due to incompatibilities between the SAL annotations in the Visual Studio 2012 C++ libraries and the Windows 7 SDK. If static analysis is required, we recommend that you switch the solution to the normal v110 toolset, execute static analysis, and then switch back to v110_xp.
     
  4. Remote Debugging
    The Remote Tools for Visual Studio 2012 do not support remote debugging on an XP client. When debugging on Windows XP is required, it is recommended to use the debuggers of an older version of Visual Studio, such as Visual Studio 2010, for local or remote debugging. This is in line with the Windows Vista experience for Visual Studio 2012 RTM, which is a runtime target but not a remote debugging target.

  5. Process Status APIs
    As with Visual Studio 2012 RTM, applications that target Windows Vista and below while taking a dependency on the process status APIs must set  the PSAPI_VERSION macro to 1.

Targeting from the Command Line

Visual Studio 2012 solutions and projects which have been switched to the v110_xp toolset can be built from the command line using MSBuild or DEVENV without additional steps. 

However, if you wish to use CL and Link directly, additional steps are needed. Note that the steps below may be automated by creating a batch script.

  1. Set the path and environment variables for Visual Studio 2012 command-line builds. 

  2. Set the required SDK paths and compiler flags using the following commands:

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

    When targeting x64, set the lib path as follows:
    set LIB=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Lib\x64;%LIB%
     
  3. Specify the correct subsystem and subsystem version for the linker based on the type of application you are building. Applications targeting the x86 version of Windows XP must specify subsystem version 5.01, and applications targeting x64 must specify version 5.02.

    For x86 console applications: 
    set LINK=/SUBSYSTEM:CONSOLE,5.01 %LINK%

    For x64 console applications:
    set LINK=/SUBSYSTEM:CONSOLE,5.02 %LINK%
     
  4. Execute CL and Link as you normally would within the command prompt.

Feedback

As always, we'd love to hear your feedback. Please submit bugs to Visual Studio Connect, and suggestions to Visual Studio UserVoice.

 

  • Why are you giving C++ 11 XP compatibility, but ignoring the cries of thousands of developers for .NET 4.5 to work on XP?  (Really, most of us would be happy with .NET 4.5 not seriously messing up XP development.)

  • @Stephen, different team.  That would require involvement of CLR team. See blogs.msdn.com/.../dotnet

  • I clicked on the download "here" link.  Which file should I be downloading for the  Update 1 CTP 3 so I can target xp?

  • I'm very eager and excited to take advantage of the improved C++ support this will make available to those of us that can't drop XP. Are there any limitations on use of C++11 features when targeting XP?

    I would be thrilled if we could have an update on how things are progressing towards the release (not CTP) version of Update 1, since I assume it would be unwise to actually ship a release build on the CTP. Within whatever limits company policy imposes, please keep us up-to-date, so we can refine our plans.

    Thank you!

  • “Remote Debugging

    The Remote Tools for Visual Studio 2012 do not support remote debugging on an XP client. When debugging on Windows XP is required, it is recommended to use the debuggers of an older version of Visual Studio, such as Visual Studio 2010, for local or remote debugging. This is in line with the Windows Vista experience for Visual Studio 2012 RTM, which is a runtime target but not a remote debugging target.”

    Use Visual Studio 2010 to debug programs built by Visual Studio 2012 ?

    Why not make the Remote Tools for Visual Studio 2012 run on XP ?

  • @Todd: There are no limitations to C++11 support when targeting Windows XP. I cannot comment on the release date, but a final CTP was released on 10/29 which fixes the known issues above. It is available through the same download link.

    @David: The remote debugger for VS2012 is designed to take advantage of new operating system features in Windows 7 and above, which prevents it from running on Windows Vista or Windows XP. If debugging with the VS2012 debugger is important for your scenarios, please post it as a suggestion on UserVoice for visibility.

  • CTP4: Many warnings:

    d:\qpsoft\mydev\include\sal_supp.h(57) : warning C4005: '__useHeader' : macro redefinition (html\parser\HTMLSourceTracker.cpp)

           D:\qpSOFT\MyDEV\include\sal.h(2872) : see previous definition of '__useHeader'

    d:\qpsoft\mydev\include\specstrings_supp.h(77) : warning C4005: '__on_failure' : macro redefinition (html\parser\HTMLSourceTracker.cpp)

           D:\qpSOFT\MyDEV\include\sal.h(2882) : see previous definition of '__on_failure'

    HTMLTokenizer.cpp

    d:\qpsoft\mydev\include\sal_supp.h(57) : warning C4005: '__useHeader' : macro redefinition (html\parser\HTMLTokenizer.cpp)

           D:\qpSOFT\MyDEV\include\sal.h(2872) : see previous definition of '__useHeader'

    d:\qpsoft\mydev\include\specstrings_supp.h(77) : warning C4005: '__on_failure' : macro redefinition (html\parser\HTMLTokenizer.cpp)

           D:\qpSOFT\MyDEV\include\sal.h(2882) : see previous definition of '__on_failure'

    HTMLTreeBuilder.cpp

    d:\qpsoft\mydev\include\sal_supp.h(57) : warning C4005: '__useHeader' : macro redefinition (html\parser\HTMLTreeBuilder.cpp)

           D:\qpSOFT\MyDEV\include\sal.h(2872) : see previous definition of '__useHeader'

    d:\qpsoft\mydev\include\specstrings_supp.h(77) : warning C4005: '__on_failure' : macro redefinition (html\parser\HTMLTreeBuilder.cpp)

           D:\qpSOFT\MyDEV\include\sal.h(2882) : see previous definition of '__on_failure'

  • @Loaden

    We modified the sal.h file in VC\include to fix this issue. It seems that your project has its own copy of sal.h (D:\qpSOFT\MyDEV\include\sal.h). If you update this file with the new version in VC\include, this should resolve the issue.

  • @Ibrahim

    It's not the sal.h copy, just itself.

    See: sal_supp.h that from Windows SDK 7.1A.

    LN26: #define __useHeader                               __declspec("SAL_useHeader()")

    and sal.h from VC/include

    LN2872:

    #ifdef _USING_V110_SDK71_ // [

    #ifndef _PREFAST_ // [

    #define __useHeader

    #else // ][

    #error Code analysis is not supported when using Visual C++ 11.0 with the Windows 7.1 SDK.

    #endif // ]

    #else // ][

    #define __useHeader                          _Use_decl_anno_impl_

    #endif // ]

    In here should changed to:

    #ifdef _USING_V110_SDK71_ // [

    #ifndef _PREFAST_ // [

    #define __useHeader

    #else // ][

    #error Code analysis is not supported when using Visual C++ 11.0 with the Windows 7.1 SDK.

    #endif // ]

    #else // ][

    #ifdef __useHeader

    #undef __useHeader

    #endif

    #define __useHeader                          _Use_decl_anno_impl_

    #endif // ]

    And same changes should go.

    LN2882:

    #ifdef _USING_V110_SDK71_ // [

    #ifndef _PREFAST_ // [

    #define __on_failure(annotes)

    #else // ][

    #error Code analysis is not supported when using Visual C++ 11.0 with the Windows 7.1 SDK.

    #endif // ]

    #else // ][

    #define __on_failure(annotes)                _On_failure_impl_(annotes _SAL_nop_impl_)

    #endif // ]

    Should be:

    #ifdef _USING_V110_SDK71_ // [

    #ifndef _PREFAST_ // [

    #define __on_failure(annotes)

    #else // ][

    #error Code analysis is not supported when using Visual C++ 11.0 with the Windows 7.1 SDK.

    #endif // ]

    #else // ][

    #ifdef __on_failure

    #undef __on_failure

    #endif

    #define __on_failure(annotes)                _On_failure_impl_(annotes _SAL_nop_impl_)

    #endif // ]

  • When's the real (final) coming out?

  • Final already have now. Thanx. Is download w/o web?  Hash available?

  • @Arlo: To download an offline version you may follow the steps here:

    supportxp.com/.../visual-studio-2012-update-1-released-download-the-full-version-for-later-offline-installation

Page 3 of 3 (42 items) 123