How to instruct GCC to stop after 5 errors?

C++GccG++

C++ Problem Overview


Is it possible to instruct GNU c++ compiler to stop after 5 errors found? Can't find this in documentation.

C++ Solutions


Solution 1 - C++

The command-line option -fmax-errors=N directs the compiler to give up after N errors. This option is present in GCC 4.6 and later.

The command-line option -Wfatal-errors directs the compiler to give up after one error. This option is present in GCC 4.0 and later.

In both cases, warnings do not count toward the limit unless you also specify -Werror.

Solution 2 - C++

You can use gcc option:

-fmax-errors=5

for this purpose.

Solution 3 - C++

I would welcome such an option as well. For now, I'm using the following workaround to get the first five errors:

<make> 2>&1|grep error|head -5

Solution 4 - C++

I have to ask why you would want to do this. Sometimes the error that exists in the code is not the first or even found in the first five errors. Sometimes it's beyond that and only is recognizable once you scroll down the list. A better method might be to break up your code and place it into smaller libraries if you're bothered by compile times. Or if you're concerned with things scrolling off the screen of a command line, using the '>>' operator to pipe the messages into a file.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionyegor256View Question on Stackoverflow
Solution 1 - C++zwolView Answer on Stackoverflow
Solution 2 - C++user1993934View Answer on Stackoverflow
Solution 3 - C++Tomasz RomanowskiView Answer on Stackoverflow
Solution 4 - C++wheatiesView Answer on Stackoverflow