multiple definition of 'globalVar'
The same symbol (variable or function) is defined in multiple source files.
extern
// In globals.h int globalVar = 10; // Definition in header // In file1.c #include "globals.h" // In file2.c #include "globals.h" // globalVar is defined again
Use extern
for declarations in header files and define variables only once.
// In globals.h extern int globalVar; // Declaration only // In globals.c int globalVar = 10; // Definition in one source file // In file1.c and file2.c #include "globals.h" // Only gets the declaration
extern
for global variables in header filesstatic
for variables that don't need to be shared