I\'m in the process of moving code written to be compiled for one chip onto another chip.
One issue that\'s come up is a multitude of multiple definition errors. Some of
The error goes away if I declare it as extern and define it in the cpp file,
The issue is that even when include guarded etc. the variable gets created once in each compilation unit - but since it is global it is pointing to same variable.
To overcome this is issue you need to either create it in anon. namespace
Something.h
namespace {
int foo = 0;
}
Or, use the static keyword
Something.h
static int foo = 0;
Both will create a different variable in each compilation unit.