In the Build Settings is it possible to treat Specific warnings as Error instead of Treating all warnings are Errors.
This is a simple Switch statement checker in xcode :
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES_Error
instead of :
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
But its not working for me.
Treat specific warnings as errors
use -Werror=
for example:
-Werror=unused-variable will treat unused variable as error, which originally treat as warning by -Wunused-variable flag
add these to Other Warning Flags in project setting.
Treat all warnings as errors except for some warnings
use -Werror and -Wno-error=
The first one will treat all warnings as errors, equals to the setting in Xcode.
And use -Wno-error= to make specific warning not be error. For example:
-Wno-error=unused-variable
add these to Other Warning Flags in project setting.
Reference https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
For all warning flags https://clang.llvm.org/docs/DiagnosticsReference.html
This link may work for you.
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html says
-Wno-error=switch makes -Wswitch warnings not be errors, even when -Werror is in effect.
Please check.
Related
When using pFUnit (3.2.9) to test my Fortran code, I get many "Illegal preprocessor directive" warnings, e.g.
Warning: Illegal preprocessor directive
/path/to/my/file/test.f90:37:2:
#line 26 "/path/to/my/file/test.f90"
1
The code compiles and runs fine, so I would like to turn off these warnings, while still seeing other compiler warnings. Which gfortran compiler flag turns this specific warning off? I am working with gfortran 7.3.1.
This is not the kind of warning that one should turn off because not using a preprocessor has usually very bad consequences on codes that use the most common directives like #define and #if. And as far as I know it isn't possible to turn it off.
It is much wiser to enable the preprocessor using the -cpp flag. Not only the warnings will stop but you will get the correct line numbers in further diagnostics as well, the line numbers will refer to your original code.
I'd like to know if it's possible to get a list of warnings that are enabled in GCC when no -Wx or -W-no-x flags are specified? I need this because I've got 2 different GCC versions (namely 3.3 and 4.3) which react differently on the same code with the same compilation flags.
For example, 4.3 with no additional warning options throws a warning when signed-to-unsigned comparison occurs while 3.3 does only if -Wsign-compare flag. So, I'd like to figure out, which flags should I add to gcc-3.3 to force it to detect the same warnings 4.3 does by default.
For 4.3 I'd managed to get such list of warnings using gcc -Q --help=warnings | grep enabled, but 3.3 doesn't seems to provide such function. Does anybody know, how it can be done in any other way? Maybe the source file that defines warning states?
Regards,
Marvin
GCC command line options are usually defined in gcc/common.opt file.
Try searching for `Warning' keyword in this file.
I am developing a BREW application. When compiling the application to get a MOD file, I am continuously getting this error:
cc1.exe: warnings being treated as errors
I want to disable this warning. I have googled it, and many say disabling -werror will help, but how can I do that?
The compiler is CodeSourcery ARM.
You need to remove -Werror from CFLAGS, CPPFLAGS etc.; these are usually set in Makefile's or build scripts.
However, I'd strongly advice to fix the actual warnings instead, which will produce more stable and error-free code.
Run this Command in Terminal to say, not to consider warning as error
make CFLAGS="-Wno-error=format-truncation"
I'm trying to Cross compile a kernel for Android using Ubuntu.
After successfully setting up the menuconfig, and compiling with the following option:
make ARCH=arm CROSS_COMPILE="arm-bravo-" -i -j10
It starts building, but then terminates with a lot of these errors:
error: variable '*something*' set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
Now I understand that this can be fixed by running gcc with --disable-werror option. Probem is that this is a huge project (kernel) and I am not well versed enough with make and Makefile, to know where I have to set this value. Kindly help me understand and fix this problem.
After weeks, I'm now in a position to answer my own question..
Look for KBUILD_CFLAGS in the main Makefile, and add the following to suppress warnings as errors:
KBUILD_CFLAGS += -w
// if all errors are to be suppressed
KBUILD_CFLAGS += -Wno-error=unused-but-set-variable
// if that specific error is to be suppressed.
I get this warning from GCC:
warning: cannot pass objects of non-POD type 'class Something' through '...'; call will abort at runtime
It's pretty deadly, especially since it calls an abort. Why isn't this an error? I would like to make it an error, but:
How do I make a specific warning an error?
Which warning is it? According to 3.8 Options to Request or Suppress Warnings, -Wno-invalid-offsetof, it looks like the flag to hide it, but it doesn't.
I'm not sure what the correct warning is, but once you've found it, you can change its disposition with the following (using 'format' as the example):
#pragma GCC diagnostic error "-Wformat"
Or as strager points out:
gcc -Werror=format ...
I've checked the gcc source for this and this specific warning cannot be disabled via command line flags.
-Werror=specific-warning will turn the specified -Wspecific-warning into an error in GCC 4.3.x or newer. In 4.1.2, only -Werror-implicit-function-declaration works. Note the hyphen instead of equals sign -- it works for that specific case only and no others. This is one of the more serious common warnings and it's definitely handy to make it into an error.
Apart from that, older versions of GCC only seem to provide the -Werror sledgehammer of making every last warning an error.
It sounds like there are a bunch of other warnings that you don't want to be turned into errors (using the -Werror flag). In general, it's good practice to fix all warnings. Using -Werror forces this.
You can use the -Werror compiler flag to turn all or some warnings into errors.
You can use -fdiagnostics-show-option to see the -W option that applies to a particular warning.
Unfortunately, in this case there isn't any specific option that covers that warning.
It appears that there will be better support for this in GCC 4.5.