Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way I can make g++ only emit warnings pertaining to my files?

Tags:

c++

c

gcc

warnings

g++

I like to compile my code with -Wall, and sometimes even -pedantic. It's partly a style thing, and partly the fact that it does occasionally emit very, very useful warnings (such as using = rather than ==).

However, the writers of some of my headers are clearly not such sticklers. Compiling with either of the two warning levels yields a tremendous mess of output, completely defeating the purpose of compiling that way in the first place.

So how can I make my compiler ignore those warnings?

like image 650
alexgolec Avatar asked Jul 08 '10 16:07

alexgolec


People also ask

Which option can be used to display compiler warnings?

You can request many specific warnings with options beginning with ' -W ', for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning ' -Wno- ' to turn off warnings; for example, -Wno-implicit .

What are compiler warnings?

Compiler warnings are messages produced by a compiler regarding program code fragments to be considered by the developer, as they may contain errors. Unlike compilation errors, warnings don't interrupt the compilation process.

Why is it a good idea to always enable compiler warnings in C?

A compiler warning signals a potentially serious problem in your code. The problems listed above are almost always fatal; others may or may not be, but you want compilation to fail even if it turns out to be a false alarm. Investigate each warning, find the root cause, and fix it.

What does the werror flag do?

The "-Werror" compiler flag treats all warnings as build errors. By promoting all warnings to errors, it enforces the developers to ensure such build warnings that may otherwise go unnoticed or only loosely concerned about by developers to now treat it with priority given that it will interrupt the build process.


1 Answers

Alternatively to JS Bangs' answer, you can have GCC treat them as system headers, which disables all warnings (excepting #warning directives) for those headers.

If the -isystem switch is unhelpful, you can wrap all of the offending headers with simpler headers that contain only the appropriate line:

#pragma GCC system_header
like image 171
greyfade Avatar answered Oct 13 '22 00:10

greyfade