From: MFDonadeli on 7 Jan 2010 12:54 Hi. I declare a singleton on a MFC extension DLL, like this: <pre> //header file: SingleTon.h class AFX_EXT_CLASS CMySingleton { public: static CMySingleton* Instance() { if(!singleton) singleton = new CMySingleton(); return singleton; } int a; // Other non-static member functions private: CMySingleton() {}; // Private constructor CMySingleton(const CMySingleton&); // Prevent copy- construction CMySingleton& operator=(const CMySingleton&); // Prevent assignment virtual ~CMySingleton() {}; static CMySingleton* singleton; }; And in a cpp file I code the following line: CMySingleton* CMySingleton::singleton = NULL; </pre> Code 2: <pre> CMySingleton *a; a = CMySingleton::Instance(); </pre> The problem is when I code "code 2" in a Regular Dll, all works fine, but when I code "code 2" in another MFC extension DLL gives an error: <pre> unresolved external symbol "private: static class CMySingleton* CMySingleton::singleton" (?singleton(a)CMySingleton@@0PAV1@A) </pre> Any idea?
From: Ajay Kalra on 7 Jan 2010 13:01 On Jan 7, 12:54 pm, MFDonadeli <mfdonad...(a)gmail.com> wrote: > Hi. > > I declare a singleton on a MFC extension DLL, like this: > > <pre> > //header file: SingleTon.h > class AFX_EXT_CLASS CMySingleton > { > public: > static CMySingleton* Instance() > { > if(!singleton) > singleton = new CMySingleton(); > return singleton; > } > > int a; > > // Other non-static member functions > private: > CMySingleton() {}; // Private > constructor > CMySingleton(const CMySingleton&); // Prevent copy- > construction > CMySingleton& operator=(const CMySingleton&); // Prevent > assignment > virtual ~CMySingleton() {}; > > static CMySingleton* singleton; > > }; > > And in a cpp file I code the following line: > > CMySingleton* CMySingleton::singleton = NULL; > </pre> > > Code 2: > <pre> > CMySingleton *a; > > a = CMySingleton::Instance(); > </pre> > > The problem is when I code "code 2" in a Regular Dll, all works fine, > but when I code "code 2" in another MFC extension DLL gives an error: > > <pre> > unresolved external symbol "private: static class CMySingleton* > CMySingleton::singleton" (?singleton(a)CMySingleton@@0PAV1@A) > </pre> > > Any idea? Are you sure you are including the correct .lib file in MFC extesion DLL where you code2 sits? -- Ajay
From: MFDonadeli on 7 Jan 2010 13:05 On 7 jan, 16:01, Ajay Kalra <ajayka...(a)yahoo.com> wrote: > On Jan 7, 12:54 pm, MFDonadeli <mfdonad...(a)gmail.com> wrote: > > > > > > > Hi. > > > I declare a singleton on a MFC extension DLL, like this: > > > <pre> > > //header file: SingleTon.h > > class AFX_EXT_CLASS CMySingleton > > { > > public: > > static CMySingleton* Instance() > > { > > if(!singleton) > > singleton = new CMySingleton(); > > return singleton; > > } > > > int a; > > > // Other non-static member functions > > private: > > CMySingleton() {}; // Private > > constructor > > CMySingleton(const CMySingleton&); // Prevent copy- > > construction > > CMySingleton& operator=(const CMySingleton&); // Prevent > > assignment > > virtual ~CMySingleton() {}; > > > static CMySingleton* singleton; > > > }; > > > And in a cpp file I code the following line: > > > CMySingleton* CMySingleton::singleton = NULL; > > </pre> > > > Code 2: > > <pre> > > CMySingleton *a; > > > a = CMySingleton::Instance(); > > </pre> > > > The problem is when I code "code 2" in a Regular Dll, all works fine, > > but when I code "code 2" in another MFC extension DLL gives an error: > > > <pre> > > unresolved external symbol "private: static class CMySingleton* > > CMySingleton::singleton" (?singleton(a)CMySingleton@@0PAV1@A) > > </pre> > > > Any idea? > > Are you sure you are including the correct .lib file in MFC extesion > DLL where you code2 sits? > > -- > Ajay Yes, via Project Dependencies on VS 2008...
From: Joseph M. Newcomer on 7 Jan 2010 13:24 Project Dependencies only indicates DEPENDENCIES. In no way, ever, under any imaginable scenario, does it actually do anything that would cause the linker to see the .lib file that is used. You must explicitly add that .lib file to the linker command line. The only thing Dependencies guarantees is that the DLL will be rebuilt before the main executable. Absolutely nothing more than that is conveyed by the concept of "dependency". joe On Thu, 7 Jan 2010 10:05:18 -0800 (PST), MFDonadeli <mfdonadeli(a)gmail.com> wrote: >On 7 jan, 16:01, Ajay Kalra <ajayka...(a)yahoo.com> wrote: >> On Jan 7, 12:54�pm, MFDonadeli <mfdonad...(a)gmail.com> wrote: >> >> >> >> >> >> > Hi. >> >> > I declare a singleton on a MFC extension DLL, like this: >> >> > <pre> >> > //header file: SingleTon.h >> > class AFX_EXT_CLASS CMySingleton >> > { >> > public: >> > � static CMySingleton* Instance() >> > � { >> > � � � � if(!singleton) >> > � � � � � � � � singleton = new CMySingleton(); >> > � � return singleton; >> > � } >> >> > � int a; >> >> > // Other non-static member functions >> > private: >> > � CMySingleton() {}; � � � � � � � � � � � � � � � � // Private >> > constructor >> > � CMySingleton(const CMySingleton&); � � � � � � � � // Prevent copy- >> > construction >> > � CMySingleton& operator=(const CMySingleton&); � � �// Prevent >> > assignment >> > � virtual ~CMySingleton() {}; >> >> > � static CMySingleton* singleton; >> >> > }; >> >> > And in a cpp file I code the following line: >> >> > CMySingleton* CMySingleton::singleton = NULL; >> > </pre> >> >> > Code 2: >> > <pre> >> > CMySingleton *a; >> >> > a = CMySingleton::Instance(); >> > </pre> >> >> > The problem is when I code "code 2" in a Regular Dll, all works fine, >> > but when I code "code 2" in another MFC extension DLL gives an error: >> >> > <pre> >> > unresolved external symbol "private: static class CMySingleton* >> > CMySingleton::singleton" (?singleton(a)CMySingleton@@0PAV1@A) >> > </pre> >> >> > Any idea? >> >> Are you sure you are including the correct .lib file in MFC extesion >> DLL where you code2 sits? >> >> -- >> Ajay > >Yes, via Project Dependencies on VS 2008... Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Ajay Kalra on 7 Jan 2010 13:26 On Jan 7, 1:05 pm, MFDonadeli <mfdonad...(a)gmail.com> wrote: > On 7 jan, 16:01, Ajay Kalra <ajayka...(a)yahoo.com> wrote: > > > > > On Jan 7, 12:54 pm, MFDonadeli <mfdonad...(a)gmail.com> wrote: > > > > Hi. > > > > I declare a singleton on a MFC extension DLL, like this: > > > > <pre> > > > //header file: SingleTon.h > > > class AFX_EXT_CLASS CMySingleton > > > { > > > public: > > > static CMySingleton* Instance() > > > { > > > if(!singleton) > > > singleton = new CMySingleton(); > > > return singleton; > > > } > > > > int a; > > > > // Other non-static member functions > > > private: > > > CMySingleton() {}; // Private > > > constructor > > > CMySingleton(const CMySingleton&); // Prevent copy- > > > construction > > > CMySingleton& operator=(const CMySingleton&); // Prevent > > > assignment > > > virtual ~CMySingleton() {}; > > > > static CMySingleton* singleton; > > > > }; > > > > And in a cpp file I code the following line: > > > > CMySingleton* CMySingleton::singleton = NULL; > > > </pre> > > > > Code 2: > > > <pre> > > > CMySingleton *a; > > > > a = CMySingleton::Instance(); > > > </pre> > > > > The problem is when I code "code 2" in a Regular Dll, all works fine, > > > but when I code "code 2" in another MFC extension DLL gives an error: > > > > <pre> > > > unresolved external symbol "private: static class CMySingleton* > > > CMySingleton::singleton" (?singleton(a)CMySingleton@@0PAV1@A) > > > </pre> > > > > Any idea? > > > Are you sure you are including the correct .lib file in MFC extesion > > DLL where you code2 sits? > > > -- > > Ajay > > Yes, via Project Dependencies on VS 2008... As Joe already pointed out, it doesnt mean much in your case. All you are ensuring is the build order as such. You need to somehow link to the library you are trying to use. How did this work for the Regular DLL for you? You would have the same problem there as well. -- Ajay
|
Next
|
Last
Pages: 1 2 3 4 5 6 Prev: Rational Robot Isnot Recognising MFC object Next: Please use wxWidgets |