用于针对XP的Visual Studio 2013的Visual C++编译器标志

kir*_*ool 3 c++ compiler-options visual-studio-2013

我想用针对XP环境的Visual Studio 2013创建一个C++程序,我知道Project Properties - > Configuration选项卡中的UI选项来设置Platform Tool set top Windows v120_xp,我想用命令实现它行选项.怎么做.

对于visual studio 2012,我知道这个选项

设置CL =/D_USING_V110_SDK71 _;%CL%

我正在寻找类似的选项是Visual Studio 2013.你能帮忙吗?

Han*_*ant 6

The _USING_V110_SDK71_ macro has nothing to do with building your program to be compatible with XP, it is merely a side-effect. The essential option is a linker option, /SUBSYSTEM. Note how this option lets you specify the major and minor sub-system version number. Your program can only run on XP if you set this option to 5,1. Starting with VS2012, the default setting is 6,0 which is the version number of the current generation of Windows. Vista or higher is required to run such a program.

This is actually rather a big deal, downgrading the version number turns on some app-compat shims in Windows that were designed to deal with a program that announces that it doesn't know anything about a modern Windows version. Particularly the way Aero lies about the window metrics, designed to allow an ancient program to still run with fat window borders.

The CRT is also affected, fairly obscure details related to threading and localization. Testing is required of course. Keep the cost of supporting such an ancient operating system in mind.

Last but not least, you also need to use an appropriate SDK version. The last one that's still compatible with XP is v7.1. If you build from the command line then you'll get 8.1, you need to fix that by setting the %WindowsSdkDir% environment variable first. And you need to set the target Windows version in your headers that #include Windows.h, hopefully a precompiled header. Define _WIN32_WINNT to 0x501 to match XP and avoid accidentally using winapi functions that are not available on XP.