在 Visual Studio 中使用参数为整个项目或解决方案定义预处理器宏的选项

2022-01-11 00:00:00 visual-studio macros c++ c-preprocessor

我希望一些具有参数的宏在项目的所有文件中都可用,或者更好的是完整的解决方案.在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.

相关文章