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

佐手、 提交于 2019-12-07 00:39:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!