Reputation: 15192
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?
Upvotes: 4
Views: 856
Reputation: 9408
See the answers to this similar question:
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.
Upvotes: 3
Reputation: 14721
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.
Upvotes: 4