views:

913

answers:

5

I'm curious if there is an option to disable gcc warnings about a parameter not being valid for the language being compiled.

Ex:

cc1: warning: command line option "-Wno-deprecated" is valid for C++/Java/ObjC++ but not for C

Our build system passes the warnings we have decided on globally across a build. We have both C/C++ code and the warnings get real annoying when trying to find actual warnings.

Any suggestions?

+1  A: 

It seems to me that if there were such an option, there would have to be a further option to turn off warnings about that option, and so on infinitely. So I suspect there isn't.

Having the same options for builds of completely different languages seems a bit odd anyway - I would have different options defined as makefile macros and used appropriately for different targets.

anon
I realize it looks odd to an outsider. I'm not in charge of the build system, Im just trying to clean it up. I don't really have the power to make the seperation of the the two.
Brian Gianforcaro
A: 

Alas gcc doesn't have ability to turn individual warnings on or off. Some warnings are special cased, and warning levels can be set, but no way to turn off warnings you don't care about.

I mean who would ever care about missing empty line at the end of the file? I know there is a patch to turn it off, but building my complier from source is a bit too much.

For your build system you might want to define separate sets of warnings for different languages. What will happen if you need to use some other compiler, not gcc?

Eugene
Our build system does support multiple compilers, 3 actually. Across 6 different architectures. GCC compiling old C code is the edge case, and -> why I asked my question..
Brian Gianforcaro
A: 

To enable specific warnings in gcc -Wxxxx and to disable them with -Wno-xxxx.

From the GCC Warning Options:

You can request many specific warnings with options beginning -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. This manual lists only one of the two forms, whichever is not the default.

However @Neil is right about separating options for different languages. If you use make you can e.g. put all C options into CFLAGS and all C++ options into CCFLAGS.

lothar
The warning option is generating the warning, I don't think -Wno*'s applicable in this case.
Brian Gianforcaro
A: 

If compiling your C files as C++ is an option for you, -x c++.

laalto
which is a very bad idea, they will bring in libstdc+++ for linking which is *huge*
cartman
Also C++ sux...
Matt Joiner
A: 

If you set the CFLAGS variable it will only effect C files, if you set CXXFLAGS variable it will only effect C++ files, so you can easily separate the logic.

cartman
It depends on his makefile
quant_dev
Indeed it does.
cartman