问题
I would like to know whether we can build the projects/binaries using visual studio 2015 which can run on Windows xp ? If its supported then how we can build ?
回答1:
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.
回答2:
As mentioned by dxiv Windows XP can be targeted from visual studio using the correct Platform toolset (Visual Studio 2015 - Windows XP (v140_xp)).
This is not in all cases sufficient. Because the vs compiler was extended by propper thread local storage (TLS) handling there is an additional change needed. The new TLS is not properly supported by Windows XP and therefore static objects in dll's will not be initialized. If you want to avoid this problem us the additional compiler flag /Zc:threadSafeInit-
to disable this problematic feature.
If you would like to use boost, you have to build it yourself. To make it compatible with Windows XP the following options have to be added :
1) run these commands before the build with b2 (bjam)
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
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%"
2) use these additional options for 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- "
Note:
- the define is _USING_V110_SDK71_ not _USING_V140_SDK71_.
- the space in
cxxflags="/Zc:threadSafeInit- "
is intentional du to a bug in b2 which would remove the trailing "-"
来源:https://stackoverflow.com/questions/34488549/targetting-windows-xp-from-visual-studio-2015-enterprise-update-1