如何消除 GCC 中的外部库/第三方警告
在我正在开发的软件项目中,我们使用某些第三方库,遗憾的是,它们会产生恼人的 gcc 警告。 我们正在努力清除所有警告代码,并希望在 GCC 中启用 treat-warnings-as-errors (-Werror) 标志。 有没有办法让这些我们无法修复的第三方生成的警告消失?
In the software project I'm working on, we use certain 3rd party libraries which, sadly, produce annoying gcc warnings.
We are striving to clean all code of warnings, and want to enable the treat-warnings-as-errors (-Werror) flag in GCC.
Is there a way to make these 3rd party generated warnings, which we cannot fix, to disappear?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
-isystem
示例:
使用 -isystem 时不会出现有关 boost 的警告:D
Use
-isystem
Example:
With -isystem NO warning about boost :D
如果您使用 CMake,则可以通过将
SYSTEM
添加到include_directories
来实现此目的:If you're using CMake, you can achieve this by adding
SYSTEM
toinclude_directories
:我认为您正在谈论来自第 3 方库标头的警告。
GCC 特定的解决方案是创建另一个包装器头文件,该文件本质上有两行:
并使用包装器而不是原始的第 3 方标头。
检查另一个SO响应详细说明了pragma。它本质上告诉 GCC 这是一个系统标头(带有递归包含的文件),并且不应生成任何警告消息。
否则,我不知道如何禁用来自第 3 方代码的警告。当然,除了暴力破解之外:在构建系统中配置要构建的文件并关闭警告。
I presume you are talking about the warnings coming from the 3rd party library headers.
The GCC specific solution would be to create another wrapper header file which has essentially the two lines:
And use the wrapper instead of the original 3rd party header.
Check another SO response detailing the pragma. It essentially tells GCC that this (with recursively included files) is a system header, and no warning messages should be generated.
Otherwise, I'm not aware how one can disable warnings coming from the 3rd party code. Except by the brute force of course: in the build system configure the files to be built with warnings off.
http://www.artima.com/cppsource/codestandards.html
http://www.artima.com/cppsource/codestandards.html