从 visual studio 2015 企业更新 1 中瞄准 Windows xp

Targetting Windows xp from visual studio 2015 enterprise update 1

我想知道我们是否可以使用 visual studio 2015 构建 projects/binaries,它可以 运行 在 Windows xp 上?如果支持,那么我们如何构建?

Configuring C++ 11 Programs for Windows XP

The Windows XP platform toolset that's included in Visual Studio is a version of the Windows 7 SDK that was included in Visual Studio 2010, but it uses the current C++ compiler. It also configures project properties to appropriate default values—for example, the specification of a compatible linker for down-level targeting. Only Windows desktop apps that are created by using the Windows XP platform toolset run on Windows XP and Windows Server 2003, but those apps can also run on more recent operating systems—for example, Windows Vista, Windows 7, Windows Server 2008, Windows 8, or Windows Server 2012.

To target Windows XP

  • In Solution Explorer, open the shortcut menu for your project, and then choose Properties.
  • In the Property Pages dialog box for the project, under Configuration Properties, General, set the Platform Toolset property to the desired Windows XP toolset. For example, choose Visual Studio 2012 – Windows XP (v110_xp) to create code that is binary compatible with the Microsoft Visual C++ 2012 Redistributable libraries.

如 dxiv 所述 Windows 可以使用正确的平台工具集从 visual studio 定位 XP (Visual Studio 2015 - Windows XP (v140_xp) ).

这在所有情况下都不够。因为 vs 编译器通过适当的线程本地存储 (TLS) 处理进行了扩展,所以需要进行额外的更改。 Windows XP 不正确支持新的 TLS,因此不会初始化 dll 中的静态对象。如果你想避免这个问题,我们可以使用额外的编译器标志 /Zc:threadSafeInit- 来禁用这个有问题的功能。

如果你想使用 boost,你必须自己构建它。为了使其与 Windows XP 兼容,必须添加以下选项:

1) 运行 使用 b2 (bjam) 构建之前的这些命令

CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
SET "INCLUDE=%ProgramFiles(x86)%\Microsoft SDKs\Windows.1A\Include;%INCLUDE%"
SET "PATH=%ProgramFiles(x86)%\Microsoft SDKs\Windows.1A\Bin;%PATH%"
SET "LIB=%ProgramFiles(x86)%\Microsoft SDKs\Windows.1A\Lib;%LIB%"

2) 对 b2 使用这些附加选项

toolset=msvc-14.0 
address-model=32 
define=BOOST_USE_WINAPI_VERSION=0x0501 
define=_USING_V110_SDK71_ 
linkflags=/SUBSYSTEM:CONSOLE,5.01 
cxxflags="/Zc:threadSafeInit- "

注:

  • 定义是 _USING_V110_SDK71_ 而不是 _USING_V140_SDK71_。
  • cxxflags="/Zc:threadSafeInit- " 中的 space 是故意的,因为 b2 中的错误会删除尾随的“-”