How to make GCC stop after first error

During compilation of a source file, GCC tries to show as many error messages as possible until it cannot make any sense of the input. This is the default behavior. For certain files, the error messages can be huge wall of text that should be navigated to find the first or first few errors. So, sometimes I would like GCC to just show me the first error and stop there.

To make GCC stop after displaying the first error:

$ gcc -Wfatal-errors foo.c

$ g++ -Wfatal-errors foo.cpp

If you use CMake to compile your code, then this directive can be added to CMakeLists.txt:


Tried with: GCC 4.9 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s