views:

168

answers:

3

I link my C++ code against several libraries (a couple of which are heavily header-based), some of which haven't been updated in a while. I've been compiling my code with -Wall and Wextra on GCC 4.0 for a while with no warnings or errors. However, now that I'm using a newer version of GCC (4.3), a number of my files have been printing warnings from the other libraries' include files (e.g., warning: type qualifiers ignored on function return type when the library's templated code uses the restrict keyword on a returned pointer). Similarly, one of the slightly older versions of OpenMPI on a cluster that I'm using prints out many warnings when compiled with GCC 4.1.

The question is: Can I do anything to disable warnings just inside other peoples' code, when leaving a local directory to read a header file? I want to make my code as clean and correct as possible (hence, I enable all warnings), but the purpose is defeated if my make process is cluttered up by problems that I'm unable to fix. Will I just have to globally disable specific warnings that crop up in their code?

+3  A: 

One thing that comes to mind is to use -isystem instead of -I when naming the include directory. This treats it as a system header, which means gcc won't show any warnings for things in them.

I'm not sure if gcc starts giving them some other treatment, though. Check the gcc documentation first, to be on the safe side.

CAdaker
I don't believe -isystem changes anything else. This has been my approach, and it has worked well. The only problem is that there may still be errors due to macro expansion in your own code (where the header defines the macro).
Paul Biggar
+3  A: 

See the answers to this similar question:

http://stackoverflow.com/questions/775774/conditionally-disable-warnings-with-qmake-gcc

My suggestion was to include 3rd party headers indirectly through wrapper headers of your own, and in those headers switch warnings off with pragmas, then back on again after the #includes for the 3rd party headers.

jon hanson
+1  A: 

Another similar question: http://stackoverflow.com/questions/525677/is-there-a-way-to-disable-all-warnings-with-a-pragma/525712

I wasn't worried about any warnings in the 3rd party libraries so simply ignored them all as described in linked post. Worked especially well as all the includes were within a pre compiled header.

Edit: Whoops, is #pragma warning just VC++?

Will
Yes, it is vc++ only. gcc doesn't seem to have fine grained warning control.
Eugene