Results 1 to 7 of 7

Thread: error: LNK1120: 1 unresolved externals

  1. #1
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default error: LNK1120: 1 unresolved externals

    Hi,
    i am using Qt 5.7

    I want to make utilize the other class functions.But I am getting the error

    searchctlr.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl utilityCtlr::utilityCtlr(void)" (??0utilityCtlr@@QEAA@XZ) referenced in function "public: void __cdecl SearchCtlr::writeXML(class QString,class QString)" (?writeXML@SearchCtlr@@QEAAXVQString@@0@Z)

    Code Snippet:

    This utility class for generic operation which is common to whole project. Ex: encryption/decryption etc.,

    utility.h
    --------
    #ifndef UTILITY_H
    #define UTILITY_H

    #include <QObject>

    class utilityCtlr : public QObject
    {

    public:

    utilityCtlr();

    void utilEncryption();

    };
    #endif // UTILITY_H

    utility.cpp
    -----------
    #include "utility.h"
    #include <QDebug>

    utilityCtlr::utilityCtlr()
    {


    }

    void utilityCtlr::utilEncryption()
    {

    QString strUserName = name;

    }

    The class calling the utility:
    searchctrl.h
    -------------

    #ifndef SEARCHCTLR_H
    #define SEARCHCTLR_H


    #include <QObject>
    //#include "search.h"

    #include "utility.h"



    class SearchCtlr : public QObject
    {
    Q_OBJECT

    public:

    explicit SearchCtlr(QObject *parent = 0);
    Q_INVOKABLE void doSearch(QString name);

    private:
    utilityCtlr *m_utilityCtlr;

    };

    searchctrl.cpp
    ---------------

    #include "searchctlr.h"
    #include <QDebug>

    #include <QDomDocument>
    #include <QFile>
    #include <QDir>
    #include<QXmlStreamReader>
    #include<QXmlStreamWriter>

    SearchCtlr::SearchCtlr(QObject *parent)
    {
    // m_search = new Search();
    // qDebug()<<__FILE__<<__LINE__<<__FUNCTION__<<"Searc hCtlr Constructor******";
    }



    void SearchCtlr::doSearch(QString name)
    {

    m_utilityCtlr = new utilityCtlr(); //Error appears when this two lines are uncommented.
    m_utilityCtlr->utilEncryption(name);

    }




















    #endif // SEARCHCTLR_H

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: error: LNK1120: 1 unresolved externals

    Looks like you haven't added utility.cpp to your project. You have #include-ed utility.h into searchCtrl.h, so the compiler "knows" there is a constructor for the class utilCtlr, but if you don't link in the utility.obj file created from utility.cpp, the linker can't find the code for it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: error: LNK1120: 1 unresolved externals

    Hi d_stranz,
    Thanks for the reply.

    but if you don't link in the utility.obj file created from utility.cpp

    could you please tell me how to do it?
    The method i followed, Added the utility.h/utility.cpp in the project through AddNew. #include "utility.h" in the SearchCtrl.H and in utility.cpp. Am I missing some steps?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: error: LNK1120: 1 unresolved externals

    Ah, I didn't notice that you had derived the utilCtlr class from QObject. You are missing the Q_OBJECT macro from the class definition:

    Qt Code:
    1. class utilityCtlr : public QObject
    2. {
    3. Q_OBJECT // <<<<<
    4. public:
    5.  
    6. utilityCtlr();
    7.  
    8. //...
    9.  
    10. };
    To copy to clipboard, switch view to plain text mode 

    If you aren't using any QObject features in your class (signals, slots, etc.) than it doesn't make much sense to derive from QObject. There is no requirement to derive C++ classes from a Qt base class in order to use the class in a Qt project.

    If this is your actual code, I think you should be getting many more link errors than just the one you show because of the missing Q_OBJECT macro.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. The following user says thank you to d_stranz for this useful post:

    Mathan (15th September 2016)

  6. #5
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: error: LNK1120: 1 unresolved externals

    Hi,
    I added the QObject, still i face the errors. Simply I create QtCPPV1.h/QtCPPV1.cpp from these files I want to access the funtions of utility.h/utility.cpp. When I try to create the object of the class I face the error.
    Code snippet:

    QtCPPV1.h
    ------------

    #include <QQuickItem>

    #include "utility.h"

    class QtCPPV1 : public QQuickItem
    {
    Q_OBJECT

    public:
    QtCPPV1(QQuickItem* parent = 0);
    ~QtCPPV1();

    Q_INVOKABLE void ss();

    private:

    utility* m_utility;

    };

    #endif // QTQCPPXMLINTEGRATIONV1_H

    QtCPPV1.cpp
    ----------------

    #include "QtCPPV1.h"
    #include <QDebug>

    QtCPPV1::QtCPPV1(QQuickItem* parent) :
    QQuickItem(parent)
    {
    m_utility = new utility();//Error appears here
    }

    QtCPPV1::~QtCPPV1()
    {
    }


    void QtCPPV1::ss()
    {

    m_utility->delEncryption();//Error appears here
    }


    utility.h
    ----------
    #ifndef UTILITY_H
    #define UTILITY_H



    #include <QXmlStreamWriter>
    #include <QByteArray>

    class utility : public QXmlStreamWriter
    {


    public:

    utility();
    ~utility();

    void delEncryption();


    };




    #endif // UTILITY_H

    utility.cpp
    ----------
    #include "utility.h"
    #include <QDebug>
    #include <QFile>



    utility::utility()
    {


    }

    utility::~utility()
    {


    }

    void utility::delEncryption()
    {


    }

  7. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: error: LNK1120: 1 unresolved externals

    Please do not just copy and paste your code into a post. It is unreadable. As I say in my sig (see below), use CODE tags. The sig even tells you how to do it.

    I don't know if you are using Qt Creator or Visual Studio to manage and build your project. If you are using Qt Creator, then you probably have not run qmake since you added (or renamed) the files in your project. If you are using Visual Studio and have correctly added all of the source files you use to your project then a "rebuild" or "clean" followed by "build" should fix this.

    There is nothing obviously wrong with your source code. The problem is almost certainly as I said earlier: utility.cpp is not being compiled and/or utility.obj is not being linked into your final binary.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. The following user says thank you to d_stranz for this useful post:

    Mathan (16th September 2016)

  9. #7
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: error: LNK1120: 1 unresolved externals

    Hi d_stranz,

    Run the Qmake and built the project as you said. Its working now. This error cost me 3hrs.

    Thanks a lot.

Similar Threads

  1. Replies: 2
    Last Post: 18th February 2016, 17:32
  2. Replies: 2
    Last Post: 7th September 2014, 17:02
  3. error unresolved externals
    By smemamian in forum Newbie
    Replies: 9
    Last Post: 3rd September 2014, 08:54
  4. Unresolved externals
    By MarkoSan in forum General Programming
    Replies: 3
    Last Post: 17th March 2007, 14:53
  5. What am I missing? Unresolved externals
    By derick in forum Qt Programming
    Replies: 49
    Last Post: 21st July 2006, 13:41

Tags for this Thread

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.