简体   繁体   中英

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

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?

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

When invoking GCC, using -isystem instead of -I to give the paths to your problematic headers should silence warnings for those headers. See the GCC docs or this SO question .

Use an appropriate #pragma to disable warnings before you include the bad headers, then re-enable the warnings afterwards. Docs on the GCC pragmas.

It seems like they're "your" headers, meaning you can modify them yourself or let the "writers" do it for you. If you want to pursue a warning free life, get those headers fixed :).

Alternatively you can of course use pragma's, but they are anti-style and ugly :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM