问题
I have two platform toolsets: v110 and v110_xp for my project, and depending on the chosen platform I want to include/exclude part of the code to be compiled.
_MSC_FULL_VER
and $(PlatformToolsetVersion)
have exactly the same value for both of these platform toolsets. Alternatively, I tried to use $(PlatformToolset)
as follows:
_MSC_PLATFORM_TOOLSET=$(PlatformToolset)
but the problem is that $(PlatformToolset)
is non-numeric. Was wondering how can I use this non-numeric value as a preprocessor directive?
Trying several solutions I figured out that
_MSC_PLATFORM_TOOLSET='$(PlatformToolset)'
and then
#if (_MSC_PLATFORM_TOOLSET=='v110')
[Something]
#endif
works fine but
#if(_MSC_PLATFORM_TOOLSET == 'v110_xp')
[SomethingElse]
#endif
results in "too many character in character constant" error.
For the context please see this similar question: Visual Studio: how to check used C++ platform toolset programmatically
回答1:
Go to project properties -> C/C++ -> Preprocessor
and add the following to Preprocessor Definitions
:
_MSC_PLATFORM_TOOLSET_$(PlatformToolset)
Then you can write something like this:
#ifdef _MSC_PLATFORM_TOOLSET_v110
[Something]
#endif
#ifdef _MSC_PLATFORM_TOOLSET_v110_xp
[SomethingElse]
#endif
This works for me in VS2010.
回答2:
For VS 2012/2013, if you use backwards-compatibility toolset, _USING_V110_SDK71_ will be available for you to use. VS2013 will define same name, regardless of platform toolset name, which is v120_xp.
#if (_MSC_VER >= 1700) && defined(_USING_V110_SDK71_)
// working in XP-compatibility mode
#endif
来源:https://stackoverflow.com/questions/23279157/visual-studio-how-to-use-platform-toolset-as-preprocessor-directive