Disable gcc warning for incompatible options

☆樱花仙子☆ 提交于 2019-12-05 10:45:38

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.

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.

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.

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?

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!