I'm working through the legacy C++ code that I'm trying to refresh.
Contractor who previously worked on the code was very sloppy and didn't bother creating headers for some of the classes and would dump everything into .cpp
, a lot of global variables, extremely large .cpp
files of upward 7000 lines of code. Right now, I'm trying to separate the code into .h
, .cpp
files.
Existing code works (compiles and runs in production). I took part of the utility code and some variables and moved them to CASupporting.h
. Compiled the project and got the following error in Visual Studio:
LNK1169 one or more multiply defined symbols found
Error LNK2005 "int * CAValidation::__invReasonCounts" (?__invReasonCounts@CAValidation@@3PAHA) already defined in AddressValidatorLib.obj
Error LNK2005 "int * CAValidation::__invReasonCounts" (?__invReasonCounts@CAValidation@@3PAHA) already defined in AddressValidatorLib.obj
Variable in questions is
//CASupporting.h
namespace CAValidation {
...
int __invReasonCounts[7] = { 0 };
...
}
I did a global search to to find out if there are any other definitions of __invReasonCounts
, but it came out empty. So, I suspect, it has to do with the way #include "CASupporting.h"
is used.
Currently the chain of includes looks like: CASupporting.h
-> CAImpl.h
-> CAImpl.cpp
& CAValidator.h
(2 files).
CAValidator.h
-> CAValidator.cpp
Out curiosity, I have moved out int __invReasonCounts[7] = { 0 };
from CASupporting.h
right into namespace CAValidation
in "CAImpl.cpp", where __invReasonCounts
is being used. Project compiles without error.