views:

2773

answers:

5

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:

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
A: 

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.

friol
+8  A: 

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.

Nik Reiman
A: 

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.

This doesn't actually answer the question.
Nick
+1  A: 

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/"

Good Person
A: 

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.

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.

Adam Davis
ffmpeg headers are valid with -pedantic -std=c99, which is what it uses to build. But I guess public headers should be valid whatever-extern-"C" is too...
alex strange