为什么 MinGW 自动包含

发布于 2024-10-28 07:30:00 字数 389 浏览 2 评论 0原文

我正在尝试以与平台无关的方式 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以往的大感动 2024-11-04 07:30:00

我的 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_ when windef.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 whether windef.h has already been included - MAKEWORD is documented as being a macro defined in windef.h, so it should be stable across SDK versions, whether from Microsoft or not.

苏别ゝ 2024-11-04 07:30:00

解决了它,

它被包含在 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文