3

Is there a way to suppress compiler warnings for GNU make and only show higher-order logs, i.e. errors?

Apparently, this should be possible using make -w as described here. However, for my version of GNU make (4.1), the man file specifies this as printing the current directory:

-w, --print-directory     Print the current directory.
-W FILE                      Consider FILE to be infinitely new.

If possible, this should be disabled both for make-internal warnings ($(warning ...)) and compiler-level warnings by gcc.

abiri
  • 95
  • 1
  • 1
  • 9
  • 1
    You seem to mix up the build system (GNU make) with the actual compiler (eg. GCC or clang) which is the one likely to emit most warnings/errors and who does have a `-w` flag to suppress all warnings. – cfillion Jun 18 '18 at 20:55
  • I should clarify: Is there a way to pass such a flag directly to the underlying `gcc` compiler, or do I have to really set all flags in the make file directly? I do not want to adjust the file itself only to temporarily disable some logs for single runs – abiri Jun 18 '18 at 21:18
  • It depends on the Makefile. https://stackoverflow.com/questions/3602927/add-compiler-option-without-editing-makefile – cfillion Jun 18 '18 at 21:21

2 Answers2

3

As pointed out in this post, it is not possible to directly add flags for the compiler. Furthermore, adding to existing CFLAGS variables (make CFLAGS+=-w) does not work either in most cases, as it ignores the append part and simply redefines the variable in the command line.

A very easy solution to fix this is by creating an empty dummy variable (once) inside your makefile and then defining it in case you need it:

# Add empty variable to add flags over command line
CDBG +=
CFLAGS += $(CDBG)

Which you then simply use as follows:

make CDBG=-w
abiri
  • 95
  • 1
  • 1
  • 9
0

as in https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

just add -w in your building command to suppress warnings, for example

gcc -Wall -w -o program pgmEcho.c pgm.c pgm.h
kingbode
  • 131
  • 2
  • 8
  • This doesn't seem to add anything useful over the accepted answer from 2018. – tripleee Aug 14 '22 at 07:26
  • 1
    this is the simple and straight forward to suppress warnings , when compiling using command line !! , no need to create variable – kingbode Aug 14 '22 at 09:44
  • Agree with @kingbode. The accepted answer adds unnecessary complexity when the simple flag is sufficient. – Joshua Cook Jan 31 '23 at 17:40