Visual Studio:如何使用平台工具集作为预处理指令? [英] Visual Studio: How to use platform toolset as preprocessor directive?

查看:270
本文介绍了Visual Studio:如何使用平台工具集作为预处理指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个平台工具集:v110和v110_xp为我的项目,并根据所选择的平台,我想包括/排除部分代码编译。

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 $(PlatformToolsetVersion)这两个平台工具集的值相同。或者,我尝试使用 $(PlatformToolset)如下:

_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)

但问题是 $(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)'

#if (_MSC_PLATFORM_TOOLSET=='v110')
  [Something]
#endif

工作正常,但

#if(_MSC_PLATFORM_TOOLSET == 'v110_xp')
  [SomethingElse]
#endif


b $ b

会导致字符常数字符过多错误。

对于上下文,请参见类似问题:
Visual Studio:如何以编程方式检查使用的C ++平台工具集

For the context please see this similar question: Visual Studio: how to check used C++ platform toolset programmatically

推荐答案

转到项目属性 - C / C ++ - >预处理程序并将以下内容添加到预处理程序定义

Go to project properties -> C/C++ -> Preprocessor and add the following to Preprocessor Definitions:

_MSC_PLATFORM_TOOLSET _ $(PlatformToolset)

然后你可以这样写:

#ifdef _MSC_PLATFORM_TOOLSET_v110
   [Something]
#endif

#ifdef _MSC_PLATFORM_TOOLSET_v110_xp
   [SomethingElse]
#endif

这适用于VS2010。

This works for me in VS2010.

这篇关于Visual Studio:如何使用平台工具集作为预处理指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆