Quick Answer
Multiple definitions of the same symbol
Understanding the Issue
This error occurs when the same variable or function is defined multiple times, violating the One Definition Rule. Common causes include forgetting header guards or defining variables in headers.
The Problem
This code demonstrates the issue:
Cpp
Error
// file.h
int global = 0; // Definition
// Included in multiple .cpp files
The Solution
Here's the corrected code:
Cpp
Fixed
// Solution: Header guards and extern
#ifndef FILE_H
#define FILE_H
extern int global; // Declaration
#endif
// file.cpp
int global = 0; // Single definition
Key Takeaways
Always use include guards and only declare (not define) in headers.