为什么 MinGW 自动包含
我正在尝试以与平台无关的方式 typedef DWORD,并且遇到以下编译器错误:
...\mingw.org\mingw_gcc_4.5.0\bin\../lib/gcc/mingw32/4.5.0/../../
../../include/windef.h:229:23: error:
'DWORD' has a previous declaration as 'typedef long unsigned int DWORD'
我希望能够依赖于我的 DWORD 实现,而不是依赖于知道它是什么的底层编译器(使用 typedef,不是宏)。
为什么 mingw (gcc 4.5.0) 在编译应用程序时自动包含“windef.h”?
如何防止这种包含?
I am trying to typedef DWORD in a platform agnostic manner, and I am running into the following compiler error:
...\mingw.org\mingw_gcc_4.5.0\bin\../lib/gcc/mingw32/4.5.0/../../
../../include/windef.h:229:23: error:
'DWORD' has a previous declaration as 'typedef long unsigned int DWORD'
I'd like to be able to depend on my implementation of DWORD and not on the underlying compiler knowing what it is (using typedefs, not macros).
Why does mingw (gcc 4.5.0) automatically include "windef.h" when an application is compiled?
How does one prevent this inclusion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的 MinGW 似乎没有自动引入
windef.h
。我怀疑您的程序包含一些其他间接拉入它的标头。您可以发布一个显示问题的简短程序吗?请注意,我看到您正在使用是否定义
_WINDEF_H
来确定这些内容是否已被 typedef'ed。这在使用 MinGW 时可能有效,但实际的 Windows SDK 在包含windef.h
时定义了_WINDEF_
- 至少有一个特定版本。我认为这是相当稳定的,但肯定有可能在某个时候发生了变化。最好键入宏
MAKEWORD
来检测windef.h
是否已包含 -MAKEWORD
被记录为宏定义在windef.h
中,因此它应该在各个 SDK 版本之间保持稳定,无论是否来自 Microsoft。My MinGW doesn't seem to automatically pull in
windef.h
. I suspect that your program is including some other header that's indirectly pulling it in. Can you post a short program that displays the problem?Note that I see you're using whether or not
_WINDEF_H
is defined to determine if these things have already been typedef'ed. That might work when MinGW is being used, but the actual Windows SDK defines_WINDEF_
whenwindef.h
is included - at least one specific version. I imagine this is fairly stable, but it's certainly possible that this has changed at some point.It might be better to key on something like the macro
MAKEWORD
to detect whetherwindef.h
has already been included -MAKEWORD
is documented as being a macro defined inwindef.h
, so it should be stable across SDK versions, whether from Microsoft or not.解决了它,
它被包含在 windows.h 中,包含在 boost 头文件中。
我定义这些 typedef 的头文件只是查找“_WINDEF_H”的存在 - 并且有一个规则,它必须是最后包含的头文件(为包含 Windows 头文件提供足够的时间,从而不需要我的类型定义)。
Solved it,
It was being included by windows.h, included by a boost header file.
My header file which defines these typedefs simply looks for the presence of "_WINDEF_H" - and has a rule that it must be the last included header file (to give sufficient time for the windows header files to become included, thereby negating the need for my typedef).