Results 1 to 4 of 4

Thread: Unresolved externals

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Unresolved externals

    Hello again!

    Once I want to compile I get following errors:

    File cdatabaseconnection.h:

    Qt Code:
    1. #ifndef CDATABASECONNECTION_H
    2. #define CDATABASECONNECTION_H
    3.  
    4. // qt headers
    5. #include <QObject>
    6. #include <QSqlDatabase>
    7.  
    8. // c++ stl headers
    9. #include <memory>
    10.  
    11. class CDatabaseConnection : public QSqlDatabase
    12. {
    13. //Q_OBJECT
    14.  
    15. public:
    16. //CDatabaseConnection(QObject *parent);
    17. static std::auto_ptr<CDatabaseConnection>& Instance(QObject *parent);
    18. ~CDatabaseConnection();
    19.  
    20. private:
    21. static std::auto_ptr<CDatabaseConnection> m_pInstance;
    22. };
    23.  
    24. //typedef std::auto_ptr<CDatabaseConnection> pdbType;
    25.  
    26. #endif // CDATABASECONNECTION_H
    To copy to clipboard, switch view to plain text mode 

    File cdatabaseconnection.cpp:

    Qt Code:
    1. #include "cdatabaseconnection.h"
    2.  
    3. /*
    4. CDatabaseConnection::CDatabaseConnection(QObject *parent)
    5.   : QSqlDatabase()
    6. {
    7. }
    8. */
    9.  
    10. CDatabaseConnection::~CDatabaseConnection()
    11. {
    12. }
    13.  
    14. std::auto_ptr<CDatabaseConnection>& CDatabaseConnection::Instance(QObject *parent)
    15. {
    16. return m_pInstance;
    17. }
    To copy to clipboard, switch view to plain text mode 

    After compilation, I get linker errors:

    Error 1 error LNK2001: unresolved external symbol "private: static class std::auto_ptr<class CDatabaseConnection> CDatabaseConnection::m_pInstance" (?m_pInstance@CDatabaseConnection@@0V?$auto_ptr@VC DatabaseConnection@@@std@@A) cdatabaseconnection.obj
    Error 2 fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\markofr.NESRAMNIK\Desktop\QBlagajna\Debug \QKlient.exe
    Can someone help me please?
    Last edited by jacek; 17th March 2007 at 16:19. Reason: changed [code] to [quote]
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Unresolved externals

    Add
    Qt Code:
    1. std::auto_ptr<CDatabaseConnection> CDatabaseConnection::m_pInstance = 0;
    To copy to clipboard, switch view to plain text mode 
    in cdatabaseconnection.cpp.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    MarkoSan (17th March 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Unresolved externals

    Quote Originally Posted by jpn View Post
    Add
    Qt Code:
    1. std::auto_ptr<CDatabaseConnection> CDatabaseConnection::m_pInstance = 0;
    To copy to clipboard, switch view to plain text mode 
    in cdatabaseconnection.cpp.
    Where should I put it, can I put it in main.cpp so I can initialize database at app beginning?
    Qt 5.3 Opensource & Creator 3.1.2

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Unresolved externals

    Quote Originally Posted by MarkoSan View Post
    Where should I put it, can I put it in main.cpp so I can initialize database at app beginning?
    An initialization of a static member is needed outside the class, in the global scope. I would strongly advise to put the definition (initialization) into cdatabaseconnection.cpp. That's where it belongs, doesn't it? You can access the pointer and initialize the actual connection anywhere you want by just including the header.
    Last edited by jpn; 17th March 2007 at 14:20. Reason: rephrased
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    MarkoSan (17th March 2007)

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 10:12
  2. link error for visual studio.net 2003
    By berlin in forum Newbie
    Replies: 9
    Last Post: 29th September 2006, 16:06
  3. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04
  4. What am I missing? Unresolved externals
    By derick in forum Qt Programming
    Replies: 49
    Last Post: 21st July 2006, 12:41
  5. Problems using DLL
    By larsli in forum Qt Programming
    Replies: 11
    Last Post: 15th July 2006, 10:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.