
LNK1169 & static const class member variables
Problem: I have an ATL project (MyDLL.dll) with two interfaces, IMy1 and IMy2.
I've added some static const class member variables to Class CMy1 as in the
example below. When I try to build the project, it compiles fine, but I get the
following link errors:
CMy1.obj : error LNK2005: "private: static long const CMy1::m_Id1" (?
CMy1.obj : error LNK2005: "private: static long const CMy1::m_Id2 (?
fatal error LNK1169: one or more multiply defined symbols found
Note: The file My1.h is included in both MyDll.cpp and My1.cpp. The first two
lines of My1.h are the usual:
#ifndef __MY1_H_
#define __MY1_H_
along with the last line:
#endif // __MY1_H_
However, the #ifndef and #define mechanism is not working. My1.h is clearly
being included twice somehow, causing these multiply defined symbols. Is there
some kind of Project configuration that I' missing here? Any ideas?
Thanks!
Chris
Here's an example of my class definition from My1.h:
class ATL_NO_VTABLE CMy1 :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CRWQuery, &CLSID_RWQuery>,
public IDispatchImpl<IRWQuery, &IID_IRWQuery, &LIBID_RECONWEBLib>
{
public:
<regular stuff here>
private:
static const long m_Identifier1;
static const long m_Identifier2;
Quote:
};
// statics initialized after class definition in global space
const long CMy1::m_identifier = 1;
const long CMy1::m_identifier = 2;