LNK2001 Error
-
I am writing an MFC DLL and I am getting the following linker error: error LNK2001: unresolved external symbol "private: static class std::basic_string,class std::allocator > CApp::m_sDllVersion" (?m_sDllVersion@CApp@@0V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) I have the CApp class decalred thus:
#pragma once #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols #include using namespace std; class CApp : public CWinApp { public: CApp(); static const char* GetDllVersion( void ); // Overrides public: virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP() private: static string m_sDllVersion; };
-
I am writing an MFC DLL and I am getting the following linker error: error LNK2001: unresolved external symbol "private: static class std::basic_string,class std::allocator > CApp::m_sDllVersion" (?m_sDllVersion@CApp@@0V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) I have the CApp class decalred thus:
#pragma once #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols #include using namespace std; class CApp : public CWinApp { public: CApp(); static const char* GetDllVersion( void ); // Overrides public: virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP() private: static string m_sDllVersion; };
You have to initialise static member variables, for instance
static string CApp::m_sDllVersion="";
inside one
.cpp
source file. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
You have to initialise static member variables, for instance
static string CApp::m_sDllVersion="";
inside one
.cpp
source file. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
No that isn't it, but thanks anyway. I had both VS6 and VS2003 installed and I think it was trying to use the wrong lib. I have now un-installed VS6 and cleared out my system path and lib variables of any reference to VS6 folders. Have re-started the PC and still have the error. At work I managed to get around the problem by telling the linker to link to a VS2003 MFC lib but I cannot now remember which one it was! I am still getting the linker error! If anyone knows of the answer I would appreciate their input. If I solve this I will post what I did in here, in case someone else encounters the same issue.
-
No that isn't it, but thanks anyway. I had both VS6 and VS2003 installed and I think it was trying to use the wrong lib. I have now un-installed VS6 and cleared out my system path and lib variables of any reference to VS6 folders. Have re-started the PC and still have the error. At work I managed to get around the problem by telling the linker to link to a VS2003 MFC lib but I cannot now remember which one it was! I am still getting the linker error! If anyone knows of the answer I would appreciate their input. If I solve this I will post what I did in here, in case someone else encounters the same issue.
-
Andy H wrote:
No that isn't it
Sure? AFAIK you MUST initialize static members.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
That is true, but maybe he's just not showing us that he has initialized it in his .cpp file. He should make it clear to us whether he has or has not done this.
I agree, on the other hand, the Linker error message content supports my hypothesis... :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.