开发者

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

开发者 https://www.devze.com 2023-01-06 07:14 出处:网络
I like to开发者_如何学C 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 usi

I like to开发者_如何学C 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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消