I ran into such problem:
I have one header file:
//first variant:
#ifndef LIBRARIES_H
#define LIBRARIES_H
const char a='4';
#endif // LIBRARIES_H
I include it in few .cpp files.
Everything works perfect.
But suddenly, if I declare a pointer:
//second variant:
#ifndef LIBRARIES_H
#define LIBRARIES_H
const char *a="asdfgh";
#endif // LIBRARIES_H
please, notice,I DECLARE ONLY ONE OF THEM(of variants).
I DECLARE a only once(I tried to change name for sadfgh or asdfg).
When I try second variant, I delete first and vise versa.
If I declare a pointer to the string I will get error “multiple inclusion of variable”.
I compile it using qt. I deleted and recompiled project a few times already.

Of course, I can define it in main() function, but I wonder, what is a reason of this problem? Why cannot I declare pointer in header file and afterwards to include it in few source code files?
means
which you can read backwards as “4 is the initial value for
awhich is a constantchar”.Since this
ais constant, it has internal linkage (i.e. it is not exposed to other translation units).On the other hand,
means
which you can read backwards as “”asdfgh” is an array used to initialize
awhich as a pointer to a constantchar”.In this case
aitself is notconst, and so does not get internal linkage by default: it has external linkage.When you include your header in two or more translation units, you therefore get two or more global and distinct objects called
a, which violates the One Definition Rule of C++ (it’s often referred to as just the ODR).One cure is to make
aitselfconst,Now try to read that backwards, to make sense of it.