How to fix C error: unknown type name 'bool'

Problem:

You have C code like

main.c
bool mybool;

but when you try to compile it you see an error message like

unknown_type_bool_output.txt
main.c: In function ‘main’:
main.c:3:5: error: unknown type name ‘bool’; did you mean ‘_Bool’?
     bool mybool;
     ^~~~
     _Bool

Solution

Add

main_fixed.c
#include <stdbool.h>

at the top of the source file where the error occured.

The reason for this error is that bool is not a standard type in C (like int or char) but only in stdbool.h.


Check out similar posts by category: C/C++, GCC Errors