LNK1169 & static const class member variables 
Author Message
 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;


Wed, 14 May 2003 03:00:00 GMT  
 LNK1169 & static const class member variables

Add a My1.cpp file and move your static definitions there.

Gabriel Kniznik


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;


Wed, 14 May 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. static const member variables?

2. dll export of static const class members

3. const static class member object

4. non-static const member ... class without a constructor

5. const class-member variable

6. How can I declare and use const member variable in a class

7. const class-member variable

8. Newbie C question regarding static & const variables

9. struct initialization (with static, const static members)

10. initializing static members variables & multiple files

11. static member variable inside class

12. write to static class member variable...

 

 
Powered by phpBB® Forum Software