禁止重复出现相同的警告?
在 Windows 上使用 MinGW (GCC),当多个源文件包含单个头文件时,如果标头具有 #warning 或“#pragma message”,则会重复多次,尽管已经报告了该警告。
有没有办法确保每次编译时 #warning 或 #pragma 仅显示一次,以免收到垃圾邮件?
我不想隐藏警告,只是重复出现相同的警告。
带有#warnings 和“#pragma message”的标头已经被正确包含保护,所以我不明白为什么#warning 会重复出现。
Using MinGW (GCC) on Windows, when a single header file is included by multiple source files, if the header has a #warning or "#pragma message", it's repeated multiple times, despite that warning having already been reported.
Is there a way to ensure that a #warning or #pragma is only shown once per compile, so as to not get spammed with messages?
I don't want to hide the warning, just repeated occurrences of the same warning.
The headers with the #warnings and "#pragma message"s are include-guarded properly already, so I don't understand why the #warning repeats itself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在标头 mycode.h 中: #define WARN_ME_OF_THIS
在代码文件 mycode.c 中:
#include "mycode.h"
mycode.h 可能会包含在多个文件中,但 mycode.c 仅编译一次,因此警告仅出现一次。您可以将 #ifdef、#warning、#endif 放在 mycode.c 中的任何位置,因此我将其离散地放在最后。
In your header mycode.h: #define WARN_ME_OF_THIS
In your code file mycode.c:
#include "mycode.h"
mycode.h may get included in multiple file but mycode.c is only compiled once so the warning only appears once. You can put the #ifdef, #warning, #endif anywhere in mycode.c so I put it discretely at the end.