Common errors

Compiler errors (“undeclared”, “implicit declaration”, “undefined reference”), warnings, and crashes such as a segmentation fault.

Runs in Zerethon IDE · C (GCC 14) Official C documentation ↗

gcc messages start with the file and line: main.c:5:12: error: …. Fix the first error first — later ones are often caused by it.

  • error: 'x' undeclared (first use in this function) — a typo, or the variable is declared in another block.
  • error: implicit declaration of function 'strlen' — a missing #include (here <string.h>), or a function used before it is declared.
  • undefined reference to 'area' — declared but never defined: the .c file with the definition is missing, misspelled, or its name starts with main/test_.
  • warning: format '%d' expects argument of type 'int' — the printf specifier does not match the value's type.
  • expected ';' before … — usually a missing semicolon at the end of the previous line.
  • Exit code 139 (signal 11, segmentation fault) — the program read or wrote memory it does not own: a NULL pointer, an index past the end of an array, or memory after free.
  • Exit code 134 (signal 6, abort) — a failed assert, or the C library found corrupted memory.

Tip: Do not ignore warnings: with -Wall -Wextra gcc points at many bugs (uninitialised variables, = instead of ==, wrong format specifiers) before they become crashes.