Limit the number of error messages from `gcc`

The error output gcccan become very large. This is especially annoying when I use static statements and are not interested in any messages that appear after an unsuccessful statement.

Is it possible to limit the number of errors reported gcc?

+4
source share
3 answers

While viewing the man page gccon -Wfatal-errors(see answer from @undur_gongor), I came across an option that directly answers my question:

-fmax-errors=n
+1
source

It’s better to move stdoutit stderrto a file so that you don’t have an exit in the shell:

gcc file.c 1> compile.log 2>&1

, head, :

gcc test.c 2>&1 | head -n 5

grep:

gcc test.c 2>&1 | grep "error"
+2

-Wfatal-errors

does gcc stop compilation on the first error detected.

If you combine it with

-Werror

you can stop at the first warning.

+2
source

Source: https://habr.com/ru/post/1617954/


All Articles