CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2016
    Posts
    2

    error LNK2001: unresolved external symbol

    i am using singulton pattern and visual studio 2010. getting this linker error.
    error LNK2001: unresolved external symbol "public: static class CAIUInterface * __cdecl CAIUInterface::GetInstance(void)" (? GetInstance@CAIUInterface@@SAPAV1@XZ) D:\15008_CPDS\CPDS\Transmitter.obj CPDS

    // this is header file.
    class CAIUInterface
    {
    private:
    static bool m_bInstanceFlag; the status of single instance creation.
    static CAIUInterface *m_objAIU;
    }

    // here is function definition.
    CAIUInterface* CAIUInterface::GetInstance()
    {
    ///Step1: Check whether instance is created
    if (!m_bInstanceFlag)
    {
    ///Step2: If instance is not created, create it newly and update the instance status to true.
    m_objAIU = new CAIUInterface();
    m_bInstanceFlag = true;
    }

    ///Step3: Return the pointer object or address of CAIUInterface instance.
    return m_objAIU;
    }



    //i am using like following.
    int CAppAIUInterface::CloseApp()
    {
    siResult = CAIUInterface::GetInstance()->Close();

    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: error LNK2001: unresolved external symbol

    I do not see where you declare this CAIUInterface::GetInstance() as static.
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2016
    Posts
    2

    Re: error LNK2001: unresolved external symbol

    Quote Originally Posted by VictorN View Post
    I do not see where you declare this CAIUInterface::GetInstance() as static.
    //here are header file details
    class CAIUInterface
    {
    private:
    static bool m_bInstanceFlag;
    static CAIUInterface *m_objAIU;


    protected:
    CAIUInterface();


    public:
    std::function<void(unsigned long)> m_fnRx1Handler;
    std::function<void(unsigned long)> m_fnRx2Handler;

    ~CAIUInterface();

    static CAIUInterface* GetInstance();

    void Printmsg(unsigned long pData);

    };

  4. #4
    Join Date
    May 2007
    Posts
    811

    Re: error LNK2001: unresolved external symbol

    And where in cpp you defined those static variables? You only declared in header and not defined them anywhere, that's why the linker is complaining, since it can not find definiton for those static member variables.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured