We are trying to compile a program on a Tandem X series machine, but we are getting errors of the form, "Illegal duplicate definition of the initialized data item in C and/or C++ ". The same code compiles successfully for us on aTandem S series machine.
We have following file Structure:
/---AddressMap.h----/
#ifndef ADDRESSMAP // Header file macro
#define ADDRESSMAP // Header file macro
typedef map<long,char*,less<long> > gAddress; data type
gAddress::iterator gAddressIterator; // define iterator
gAddress gAddressMap; // define variable
#endif//ADDRESSMAP
/*file1.cpp:-> First File using the AddressMap */
#include "AddressMap.h" // include file
/*file2.cpp:-> Second File also using the AddressMap */
#include "AddressMap.h" // include file
Problem
Both files are compiled successfully, but linking them together fails with ...
Illegal duplicate definition of the initialized data item gAddressMap in file1.o and in file2.o
Since both files need to access this variable, both have included the header file; maybe that's responsible for the error. Also, it's existing code, so we want to avoid major code change. In particular, we want to keep the same header file and variable names.
How can we resolve this error?
Tandem Details:
- X series
- Linker used is xld (nld is not available on this series)