简体   繁体   中英

Visual Studio: How to use platform toolset as preprocessor directive?

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM