why is this happening?
Because the variable is declared static
. This means that the variable has internal linkage. Which means that each translation unit has their own object. You have defined the variable in two translation units, and therefore you have two objects.
If you didn't want this, then the variable shouldn't be static
. An easy solution is to declare it inline
instead. This allows it to have external linkage while still being defined in the header.
P.S. Be very careful of Static Initialisation Order Fiasco. Try to avoid variables of static storage when you can, especially those in namespace scope.