如何忽略外部库头中的gcc编译器学究错误?

时间:2021-10-24 09:43:26

I recently added -pedantic and -pedantic-errors to my make gcc compile options to help cleanup my cross platform code. All was fine until it finds errors in external included header files. Is there a way to turn off this error checking in external header files IE:

我最近在make gcc编译选项中添加了-pedantic和-pedantic-errors来帮助清理我的跨平台代码。一切都很好,直到它在外部包含的头文件中发现错误。有没有办法在外部头文件IE中关闭此错误检查:

Keep checking for files included like this:

继续检查包含的文件如下:

#include "myheader.h"

Stop checking for include files like this:

停止检查包含这样的包含文件:

#include <externalheader.h>

Here are the errors I am getting:

以下是我得到的错误:

g++ -Wall -Wextra -Wno-long-long -Wno-unused-parameter -pedantic --pedantic-errors
-O3 -D_FILE_OFFSET_BITS=64 -DMINGW -I"freetype/include" -I"jpeg" -I"lpng128" -I"zlib"
-I"mysql/include" -I"ffmpeg/libswscale" -I"ffmpeg/libavformat" -I"ffmpeg/libavcodec"
-I"ffmpeg/libavutil" -o omingwd/kguimovie.o -c kguimovie.cpp

In file included from ffmpeg/libavutil/avutil.h:41,
             from ffmpeg/libavcodec/avcodec.h:30,
             from kguimovie.cpp:44:
ffmpeg/libavutil/mathematics.h:32: error: comma at end of enumerator list
In file included from ffmpeg/libavcodec/avcodec.h:30,
             from kguimovie.cpp:44:
ffmpeg/libavutil/avutil.h:110: error: comma at end of enumerator list
In file included from kguimovie.cpp:44:
ffmpeg/libavcodec/avcodec.h:277: error: comma at end of enumerator list
ffmpeg/libavcodec/avcodec.h:303: error: comma at end of enumerator list
ffmpeg/libavcodec/avcodec.h:334: error: comma at end of enumerator list
ffmpeg/libavcodec/avcodec.h:345: error: comma at end of enumerator list
ffmpeg/libavcodec/avcodec.h:2249: warning: `ImgReSampleContext' is deprecated
(declared at ffmpeg/libavcodec/avcodec.h:2243)
ffmpeg/libavcodec/avcodec.h:2259: warning: `ImgReSampleContext' is deprecated
(declared at ffmpeg/libavcodec/avcodec.h:2243)
In file included from kguimovie.cpp:45:
ffmpeg/libavformat/avformat.h:262: error: comma at end of enumerator list
In file included from ffmpeg/libavformat/rtsp.h:26,
             from ffmpeg/libavformat/avformat.h:465,
             from kguimovie.cpp:45:
ffmpeg/libavformat/rtspcodes.h:38: error: comma at end of enumerator list
In file included from ffmpeg/libavformat/avformat.h:465,
             from kguimovie.cpp:45:
ffmpeg/libavformat/rtsp.h:32: error: comma at end of enumerator list
ffmpeg/libavformat/rtsp.h:69: error: comma at end of enumerator list

5 个解决方案

#1


-2  

You could fix the headers and submit a patch to ffmpeg; compatibility with -pedantic is a worthy goal so I'm sure they'd consider it, especially if it just involved removing trailing commas and suchlike.

您可以修复标题并向ffmpeg提交补丁;与-pedantic的兼容性是一个有价值的目标,所以我相信他们会考虑它,特别是如果它只涉及删除尾随逗号等。

#2


31  

Using the -Wsystem-headers option with gcc will print warning messages associated with system headers, which are normally suppressed. However, you're looking to have gcc basically treat these files as system headers, so you might try passing "-isystem /usr/local/ffmpeg" (or wherever you installed that package) to get gcc to ignore errors from files included in these directories as well.

在gcc中使用-Wsystem-headers选项将打印与系统头相关联的警告消息,这些消息通常被抑制。但是,您希望gcc基本上将这些文件视为系统头文件,因此您可以尝试传递“-isystem / usr / local / ffmpeg”(或安装该软件包的任何地方)以使gcc忽略包含在文件中的文件中的错误这些目录也是如此。

#3


1  

I don't know of any way to tell gcc to stop emitting those warnings. However you could hackishly remove third-party warnings with something like llvm-gcc (or just gcc) -pedantic 2>&1|grep -v "/usr/"

我不知道有什么方法可以告诉gcc停止发出这些警告。但是你可以用llvm-gcc(或者只是gcc)-pedantic 2>&1 | grep -v“/ usr /”这样的东西来骇人地删除第三方警告

#4


0  

One idea that comes to my mind (don't know if there's an 'out of the box' parameter for this):

我想到了一个想法(不知道是否有“开箱即用”的参数):

Prepare a script that will take your compiler's output, and remove all the lines that contain headers that aren't in a specific list (your headers).

准备一个脚本,该脚本将获取编译器的输出,并删除包含不在特定列表(标题)中的标题的所有行。

Shouldn't be that hard doing it this way.

不应该这样做这么难。

#5


-2  

You can't tell GCC to be pedantic about some headers and not others at this time. You might suggest it as a feature, although I suspect it'll be resisted as ideally everyone would be pedantic.

你不能告诉GCC在这个时候对某些标题而不是其他标题是迂腐的。你可能会建议它作为一个功能,虽然我怀疑它会受到抵制,因为理想情况下每个人都会迂腐。

What you can do is fix the headers yourself, generate a patch, and then apply that patch to later versions of the headers if you upgrade the library.

您可以做的是自行修复标头,生成修补程序,然后在升级库时将该修补程序应用于更高版本的标头。

Submit the patch to ffmpeg as well in the hopes that they'll adopt it, but either way you're covered even if they don't accept it.

将补丁提交给ffmpeg,希望他们能够采用它,但无论哪种方式,即使他们不接受,你也会被覆盖。

#1


-2  

You could fix the headers and submit a patch to ffmpeg; compatibility with -pedantic is a worthy goal so I'm sure they'd consider it, especially if it just involved removing trailing commas and suchlike.

您可以修复标题并向ffmpeg提交补丁;与-pedantic的兼容性是一个有价值的目标,所以我相信他们会考虑它,特别是如果它只涉及删除尾随逗号等。

#2


31  

Using the -Wsystem-headers option with gcc will print warning messages associated with system headers, which are normally suppressed. However, you're looking to have gcc basically treat these files as system headers, so you might try passing "-isystem /usr/local/ffmpeg" (or wherever you installed that package) to get gcc to ignore errors from files included in these directories as well.

在gcc中使用-Wsystem-headers选项将打印与系统头相关联的警告消息,这些消息通常被抑制。但是,您希望gcc基本上将这些文件视为系统头文件,因此您可以尝试传递“-isystem / usr / local / ffmpeg”(或安装该软件包的任何地方)以使gcc忽略包含在文件中的文件中的错误这些目录也是如此。

#3


1  

I don't know of any way to tell gcc to stop emitting those warnings. However you could hackishly remove third-party warnings with something like llvm-gcc (or just gcc) -pedantic 2>&1|grep -v "/usr/"

我不知道有什么方法可以告诉gcc停止发出这些警告。但是你可以用llvm-gcc(或者只是gcc)-pedantic 2>&1 | grep -v“/ usr /”这样的东西来骇人地删除第三方警告

#4


0  

One idea that comes to my mind (don't know if there's an 'out of the box' parameter for this):

我想到了一个想法(不知道是否有“开箱即用”的参数):

Prepare a script that will take your compiler's output, and remove all the lines that contain headers that aren't in a specific list (your headers).

准备一个脚本,该脚本将获取编译器的输出,并删除包含不在特定列表(标题)中的标题的所有行。

Shouldn't be that hard doing it this way.

不应该这样做这么难。

#5


-2  

You can't tell GCC to be pedantic about some headers and not others at this time. You might suggest it as a feature, although I suspect it'll be resisted as ideally everyone would be pedantic.

你不能告诉GCC在这个时候对某些标题而不是其他标题是迂腐的。你可能会建议它作为一个功能,虽然我怀疑它会受到抵制,因为理想情况下每个人都会迂腐。

What you can do is fix the headers yourself, generate a patch, and then apply that patch to later versions of the headers if you upgrade the library.

您可以做的是自行修复标头,生成修补程序,然后在升级库时将该修补程序应用于更高版本的标头。

Submit the patch to ffmpeg as well in the hopes that they'll adopt it, but either way you're covered even if they don't accept it.

将补丁提交给ffmpeg,希望他们能够采用它,但无论哪种方式,即使他们不接受,你也会被覆盖。