如何消除 GCC 中的外部库/第三方警告

发布于 2024-09-11 03:05:46 字数 146 浏览 1 评论 0原文

在我正在开发的软件项目中,我们使用某些第三方库,遗憾的是,它们会产生恼人的 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 技术交流群。

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

发布评论

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

评论(4

使用-isystem
示例:

gcc -I./src/ -isystem /usr/include/boost/ -c file.c -o obj/file.o

使用 -isystem 时不会出现有关 boost 的警告:D

Use -isystem
Example:

gcc -I./src/ -isystem /usr/include/boost/ -c file.c -o obj/file.o

With -isystem NO warning about boost :D

半岛未凉 2024-09-18 03:05:47

如果您使用 CMake,则可以通过将 SYSTEM 添加到 include_directories 来实现此目的:

include_directories(SYSTEM "${LIB_DIR}/Include")
                    ^^^^^^

If you're using CMake, you can achieve this by adding SYSTEM to include_directories:

include_directories(SYSTEM "${LIB_DIR}/Include")
                    ^^^^^^
过去的过去 2024-09-18 03:05:47

我认为您正在谈论来自第 3 方库标头的警告。

GCC 特定的解决方案是创建另一个包装器头文件,该文件本质上有两行:

#pragma GCC system_header
#include "real_3rd_party_header.h"

并使用包装器而不是原始的第 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:

#pragma GCC system_header
#include "real_3rd_party_header.h"

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.

野却迷人 2024-09-18 03:05:47

http://www.artima.com/cppsource/codestandards.html

示例1:第三方头文件。
一个你不能的库头文件
变化可能包含一个结构
引起(可能是良性的)警告。
然后用你自己的文件包装
#includes 原始版本
标头并有选择地关闭
仅针对该范围的噪音警告,
然后 #include 你的包装器
贯穿项目的其余部分。

http://www.artima.com/cppsource/codestandards.html

Example 1: A third-party header file.
A library header file that you cannot
change could contain a construct that
causes (probably benign) warnings.
Then wrap the file with your own
version that #includes the original
header and selectively turns off the
noisy warnings for that scope only,
and then #include your wrapper
throughout the rest of your project.

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