Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. LNK2001 Error

LNK2001 Error

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestionlearning
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andy H
    wrote on last edited by
    #1

    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; };

    CPalliniC 1 Reply Last reply
    0
    • A Andy H

      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; };

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #2

      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.

      In testa che avete, signor di Ceprano?

      A 1 Reply Last reply
      0
      • CPalliniC CPallini

        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.

        A Offline
        A Offline
        Andy H
        wrote on last edited by
        #3

        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.

        CPalliniC 1 Reply Last reply
        0
        • A Andy H

          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.

          CPalliniC Online
          CPalliniC Online
          CPallini
          wrote on last edited by
          #4

          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.

          In testa che avete, signor di Ceprano?

          C 1 Reply Last reply
          0
          • CPalliniC CPallini

            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.

            C Offline
            C Offline
            Cyrilix
            wrote on last edited by
            #5

            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.

            CPalliniC 1 Reply Last reply
            0
            • C Cyrilix

              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.

              CPalliniC Online
              CPalliniC Online
              CPallini
              wrote on last edited by
              #6

              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.

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups