Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to make GCC stop after first error

📅 2014-Jun-18 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

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