scope g++ pedantic compile

481 views Asked by At

Is it possible to restict the -pedantic switch for certain files? For example I compile stuff using alsa-lib, which I refer with standard

#include <alsa/asoundlib.h>

however -pedantic panics on this file. I am willing and interested in correcting warning and oddities in my own code, but not in alsa and other unrelated third parties.

Is there a way to scope the -pedantic usage?

2

There are 2 answers

1
AudioBubble On BEST ANSWER

Normally, GCC suppresses warnings in system headers, unless you explicitly specify -Wsystem-headers. And normally, files included with <> from /usr/include are treated as system headers. Your question suggests you specifically added something that makes GCC not treat it as a system header. You haven't specified which compiler options you're using, but are you adding any pointless -I* options that might make /usr/include get treated as a non-system header directory?

If all else fails, you can use the -isystem to actually add directories as system header directories, but you shouldn't need that here.

Edit: after re-reading the question, if you installed alsa-lib in a non-standard path, then my remark that you should not need the -isystem option may be wrong: it may be exactly what you need.

0
Lol4t0 On

You can scope any compilation key to one compilation unit.

Apperently, if you has multiple compilation units you can use deferent keys to compile them:

g++ -pedantic file_that_does_not_use_ugly_alsa.cpp
g++ file_that_uses_ugly_alsa.cpp

But you you can not scope keys inside compilation unit: code get prepropcessed before compiling, all headers are inlined and actually after macros substitution you may find out that your code uses some things, that make compiler panic.