找到一些宏被#define-ed的地方 [英] Find place where some macro was #define-ed
问题描述
底线:使用 VS2012 构建,在我的项目中定义了一个宏 (WIN32_LEAN_AND_MEAN) 我在任何地方都找不到 #define-ed:不在 C/C++ 中 --> 预处理器,不是从父项或项目依赖项继承的(microsoft.cpp.props),而不是在命令行中.在 vcxproj 中的任何地方都没有提到它.
The bottom line: building with VS2012, there's a macro (WIN32_LEAN_AND_MEAN) defined in my project I can't find #define-ed anywhere: not in C/C++ --> Preprocessor, not inherited from parent or project dependencies (microsoft.cpp.props), not in the command-line. It is not mentioned anywhere in the vcxproj.
在项目中编译单个源/头文件,我发现它已经定义在头文件的第一行.将此放在我的标题顶部:
Compiling a single source/header in the project, I find it is defined already on the first line of the header. Putting this at the top of my header:
#pragma once
#ifndef WIN32_LEAN_AND_MEAN
#pragma message ("WIN32_LEAN_AND_MEAN not defined")
#else
#pragma message ("WIN32_LEAN_AND_MEAN defined")
#endif
/* ... */
将WIN32_LEAN_AND_MEAN 定义
"打印到构建输出控制台.
Printed "WIN32_LEAN_AND_MEAN defined
" to the build output console.
根据在另一个非常相似的问题中发布的建议,我尝试重新定义宏:
According to suggestions that were posted in another - very similar - question, I tried to re-define the macro:
#define WIN32_LEAN_AND_MEAN 123
#ifndef WIN32_LEAN_AND_MEAN
#pragma message ("WIN32_LEAN_AND_MEAN not defined")
#else
#pragma message ("WIN32_LEAN_AND_MEAN defined")
#endif
显然会收到构建警告:
C:\sys\inc\myproj\myproj_someheader.h(5):警告 C4005:'WIN32_LEAN_AND_MEAN':宏重新定义
C:\sys\inc\myproj\myproj_someheader.h(5): warning C4005: 'WIN32_LEAN_AND_MEAN' : macro redefinition
命令行参数:参见'WIN32_LEAN_AND_MEAN'的先前定义
command-line arguments : see previous definition of 'WIN32_LEAN_AND_MEAN'
但是,如前所述,当前定义的宏不是在该项目配置 (vcxproj
) 中,也不是在任何公共属性中.
However, as previously mentioned, not in that project configuration (vcxproj
), and also not in any common properties, is that macro currently defined.
我的问题是:我怎样才能找到那个宏实际上来自哪里?
My question is: How can I find where that macro actually came from?
推荐答案
查看项目属性(Project Properties->C/C++->Preprocessor->Preprocessor Definitions and at C/C++->Command Line)后,vcxproj 本身(查看是否为特定源文件配置了预处理器定义)、通用属性(在 Microsoft.Cpp.Props 中配置)、头文件和源代码,没有任何地方定义 WIN32_LEAN_AND_MEAN,事实证明它是由 %CL% 环境变量.
After looking at the project properties (Project Properties->C/C++->Preprocessor->Preprocessor Definitions and at C/C++->Command Line), the vcxproj itself (looked if there are Preprocessor Definitions configured for the specific source file), common properties (configured in Microsoft.Cpp.Props), headers and source-code, nowhere where WIN32_LEAN_AND_MEAN was defined, it turns out it was defined by the %CL% environment variable.
这篇关于找到一些宏被#define-ed的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!