2023-12-21 06:04 AM
2023-12-21 06:26 AM
If you have multiple compilations units (i.e. multiple *.c files), this gets included from each of them (only once). When the linker tries to resolve everything at the end, it sees multiple definitions of ledState.
Solution: don't put variables definitions in header files. Put them in source files. If you need them in multiple source files, additional put an "extern" declaration in the header.
In a header file:
extern bool ledState;
In one source file:
bool ledState = false;
2023-12-21 06:26 AM
If you have multiple compilations units (i.e. multiple *.c files), this gets included from each of them (only once). When the linker tries to resolve everything at the end, it sees multiple definitions of ledState.
Solution: don't put variables definitions in header files. Put them in source files. If you need them in multiple source files, additional put an "extern" declaration in the header.
In a header file:
extern bool ledState;
In one source file:
bool ledState = false;