Multiple definition is a linker error.
It is a violation of the
One Definition Rule, you've got several translation units that define the same function or variable.
This is common caused because you put the
definition of a function in a header file. Then all the sources that include that header would have that function definition (it doesn't matter that all definitions are the
same)
The header should only have function
declarations, move the definitions to a source file and link it to your project
(see also
[faq] undefined reference http://www.cplusplus.com/forum/general/113904/ )
Note: you may also have the error if you
#include
a .cpp file. Don't do that.
Global variables
So you want a variable to be visible anywhere in your code. So you declared it global in a header, and put an
#include
in the sources want to use it.
To declare a global variable use
extern
, by instance
extern nih::ostream cout;
You do need to define the variable in one source file.
Template and inline
These are an exception. Their definition is needed at compile time, so a special case is generated and you would not have
multiple definition errors.
Simply put the definition in a header file.