Hi again. New problem. I creaated a new project that only has main.c file1.c and file1.h
file1.h is #included in main.c which contains a global variable.
When I build all I get :- .\scope.axf: Error: L6200E: Symbol global_VAR multiply defined (by main.o and file.o).
How do I get round this?
I have googled around but don't quite understand the issue.
But that isn't part of the C standard - it was basically a spin-off from how linkers are required to handle some constructs (like templates and inline functions) in C++.
Erm, no. C++ had nothing to do with that. Merging common definitions occuring in multiple modules is a feature that predates C++ by at least a decade. It was common in Unix linkers, because those had to be able to link not only C programs, but also FORTRAN programs, and programs built from a mix of FORTRAN and C modules, too. Even the official C standard mentions this behaviour as a "common extension" (C99 J.5.11).
The reason for this was that FORTRAN had only a very weak equivalent of a global variable definition, which also had to do double duty as the only kind of data structure it supported besides arrays: the named COMMON block. Since the there was no distinction between definition and declaration, those named COMMONs had to be defined by every module that used them, and it was then up to the linker to merge these repeated definitions.
Some C++ tool chains may have re-used this functionality for inlines and template instantiations (before they came to their senses and did it properly, using weak symbols). But it existed a long time before C++ did.