Now that we know the steps in the compilation process, it is easier to understand error messages. For example, if there is an error in a
#include directive, you’ll get a message from the preprocessor:
hello.c:1:20: fatal error: stdioo.h: No such file or directory compilation terminated.
If there’s a syntax error, you get a message from the compiler:
hello.c: In function 'main': hello.c:6:1: error: expected ';' before '}' token
If you use a function that’s not defined in any of the standard libraries, you get a message from the linker:
/tmp/cc7iAUbN.o: In function `main': hello.c:(.text+0xf): undefined reference to `printff' collect2: error: ld returned 1 exit status
ld is the name of the UNIX linker, so named because “loading” is another step in the compilation process that is closely related to linking.
Once the program starts, C does very little runtime checking, so there are only a few runtime errors you are likely to see. If you divide by zero, or perform another illegal floating-point operation, you will get a “Floating point exception.” And if you try to read or write an incorrect location in memory, you will get a “Segmentation fault.”