在 Visual Studio 中使用参数为整个项目或解决方案定义预处理器宏的选项 [英] Options for defining preprocessor macros with parameters for entire project or solution in Visual Studio

查看:26
本文介绍了在 Visual Studio 中使用参数为整个项目或解决方案定义预处理器宏的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望一些具有参数的宏在项目的所有文件中都可用,或者更好的是完整的解决方案.在VS2010中,如果我将它们添加到属性->配置属性->C/C++->预处理器中的预处理器定义中,使用类似的东西

I want some macros having parameters to be available in all files in a project or better a complete solution. In VS2010, if I add them to the Preprocessor Definitions in properties->Configuration Properties->C/C++->Preprocessor using something like

SQUARE(x)=((x)*(x));CUBE(x)=(SQUARE(x)*x); 

编译器不使用宏定义.然而,这种方法可能很接近,因为当我将鼠标悬停在源代码中的宏上时,IntelliSense 提供了正确的定义.

the macro definitions are not used by the compiler. However the approach may be close since IntelliSense provides the correct definitions when I hover over the macros in the source code.

有没有一种方法可以定义宏并使它们可见,而无需在每个文件中包含带有其定义的标题?

Is there a way to define the macros and make them visible without including a header with their definitions in every file?

感谢您的任何想法!

推荐答案

将宏放在文件中,并使用/FI 选项自动将其包含到所有文件中:

Place the macro in a file and automatically include it into all files using the /FI option:

https://msdn.microsoft.com/en-us/library/8c5ztk84.aspx

语法:/FI[ ]路径名

Syntax: /FI[ ]pathname

/FI 选项与将文件包含在每个源文件的顶部具有相同的效果.

The /FI option has the same effect as including the file at top of every source file.

这篇关于在 Visual Studio 中使用参数为整个项目或解决方案定义预处理器宏的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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