如何忽略外部库头中的gcc编译器迂回错误?
我最近添加了-pedantic和-pedantic-errors给我的gcc编译选项来帮助清理我的跨平台代码。一切都很好,直到它在外部包含的头文件中发现错误。有没有办法关闭这个错误在外部头检查文件IE:如何忽略外部库头中的gcc编译器迂回错误?
保持检查的文件包括如下:
#include "myheader.h"
停止检查包含文件是这样的:
#include <externalheader.h>
这里是我得到的错误:
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
你可以修复头文件并将补丁提交给ffmpeg;与-pedantic
兼容是一个有价值的目标,所以我相信他们会考虑它,特别是如果它只是删除尾随逗号等。
想到一个想法(不要知道如果有这种的“开箱即用”参数):
编写一个脚本,将你的编译器的输出,并删除所有包含不在特定列表(你标题标题行)。
这样做不应该那么辛苦。
对gcc使用-Wsystem-headers选项将打印与系统标题相关的警告消息,这些消息通常会被抑制。然而,你希望gcc基本上把这些文件当作系统头文件,所以你可以尝试传递“-isystem/usr/local/ffmpeg”(或者你安装那个包的地方)来让gcc忽略包含在文件中的错误这些目录也是如此。
太棒了!答案应该已被接受! – 2011-07-01 13:58:05
我不知道有什么办法告诉gcc停止发出这些警告。然而,你可以用类似llvm-gcc(或者仅仅是gcc)-pedantic 2的方式冒充地删除第三方警告> & 1 | grep -v“/ usr /”
你不能告诉GCC关于某些东西而不是其他人。你可能会认为它是一个功能,尽管我怀疑它会被拒绝,理想上每个人都会变得迂腐。
您可以做的是自己修复头文件,生成补丁程序,然后将该补丁程序应用于更高版本的头文件(如果升级该库)。
将修补程序提交给ffmpeg,希望他们能够采用它,但是无论哪种方式,即使他们不接受它,也会覆盖你。
这实际上并没有回答这个问题。 – Nick 2009-03-19 17:00:52
@KPexEA:请考虑重新分配接受的明显更好的答案 - 帮助SO搜索结果和人类读者发现答案。 – sehe 2011-11-03 23:29:27