Results 1 to 12 of 12

Thread: "Undefined reference to" in QtCreator plugin

  1. #1
    Join Date
    Nov 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default "Undefined reference to" in QtCreator plugin

    Hi,
    I´m developing a plugin for QtCreator 2.0.1 (based on Qt 4.7.0) on a Windows machine.
    My plugin would be a key-logger; to achieve this I thought about having a static method in my plugin that will instantiate an object for writing the data from the file, the static method is then called by the CppEditor plugin (by modifying it manually).
    When compiling with mingw32 i get an "undefined reference to LoggerProxy()" that is my object.
    Can somebody help me fixing this? I´m quite new to Qt and C++ in general.
    Thank you

  2. #2
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: "Undefined reference to" in QtCreator plugin

    #include <Logger.h>
    #include <qlog/qlog.h>

    Included??

  3. #3
    Join Date
    Nov 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: "Undefined reference to" in QtCreator plugin

    in my main class (the one that implements IPlugin), LoggerPlugin, I included LoggerProxy.h that is the header that defines the object.
    what is that qlog.h? Why I would need it?
    Thank you

  4. #4
    Join Date
    Nov 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: "Undefined reference to" in QtCreator plugin

    what I have noticed after some tries is that if I move the code of my object from the .cpp file to the .h file mingw32 doesn't complain at all while compiling.
    Any advice?

  5. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: "Undefined reference to" in QtCreator plugin

    Show the code, it's almost impossible to help without seeing it.

  6. #6
    Join Date
    Nov 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: "Undefined reference to" in QtCreator plugin

    LoggerPlugin.h
    Qt Code:
    1. #ifndef LOGGERPLUGIN_H
    2. #define LOGGERPLUGIN_H
    3. #include <QTextStream>
    4. #include <QtPlugin>
    5. #include <QStringList>
    6. #include <QMessageBox>
    7. #include <QString>
    8. #include <QtCore/QDebug>
    9. #include <Logger/xmlproxy.h>
    10.  
    11.  
    12.  
    13.  
    14. class LoggerPlugin : public ExtensionSystem::IPlugin
    15. {
    16.  
    17. private:
    18. QString lookupName(int id);
    19. int lookupID(QString name);
    20.  
    21. public:
    22.  
    23. XMLLoggerPlugin();
    24. ~XMLLoggerPlugin();
    25. void extensionsInitialized();
    26. bool initialize(const QStringList & arguments, QString * errorString);
    27. void shutdown();
    28.  
    29. // this is the method called by CppEditor. It just instantiate my proxy object.
    30. static void register(QString name, QString filename, QString type){
    31. XMLProxy pr(name, filename, type);
    32. }
    33. };
    34. #endif // LOGGERPLUGIN_H
    To copy to clipboard, switch view to plain text mode 

    LoggerPlugin.cpp then contains the implementation of the initialize and shutdown methods, but nothing tricky just clean-up code.

    XMLProxy.h
    Qt Code:
    1. #ifndef XMLPROXY_H
    2. #define XMLPROXY_H
    3. class XMLProxy
    4. {
    5. public:
    6. XMLProxy();
    7. ~XMLProxy();
    8. XMLProxy(QString name, QString filename, QString type);
    9. void serializeXML();
    10. QString _name, _filename, _type;
    11. };
    12.  
    13. #endif // XMLPROXY_H
    To copy to clipboard, switch view to plain text mode 

    and the class implementation
    XMLProxy.cpp
    Qt Code:
    1. #include <QDateTime>
    2. #include <QFile>
    3. #include <QXmlStreamWriter>
    4. #include <QDate>
    5. #include <extensionsystem/iplugin.h>
    6. #include <QtXml/QDomDocument>
    7. #include <QtXml/QDomElement>
    8. #include <QtXml/QDomText>
    9. #include "xmlproxy.h"
    10. XMLProxy::XMLProxy(){}
    11. XMLProxy::XMLProxy(QString name, QString filename, QString type){
    12. this->_name=name;
    13. this->_filename=namefilename;
    14. this->_type=type;
    15. }
    16.  
    17. XMLProxy::serializeXML(){
    18. //stub of the method to serialize a XMLProxy to a XML file
    19. QFile file("Logfile.xml");
    20. QDomDocument doc("Events");
    21. QDomElement ev = doc.createElement("event");
    22. QDomElement typeNode = doc.createElement("type");
    23. QDomText typeTxt = doc.createTextNode(this->_type);
    24. typeNode.appendChild(typeTxt);
    25. ev.appendChild(typeNode);
    26. //...to be cont´d
    27. }
    To copy to clipboard, switch view to plain text mode 

    it´s not working like this but if I move the code from XMLProxy.cpp to XMLProxy.h it works
    To compile I do "qmake ..\qtcreator.pro -recursive CONFIG+=debug QT+=xml" from the build directory of qtcreator folder and then, from the same dir, "mingw32-make debug"

    Thank you for any help

  7. #7
    Join Date
    Nov 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: "Undefined reference to" in QtCreator plugin

    That´s the output after executing mingw32-make

    g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
    oc -Wl,-s -mthreads -Wl -shared -Wl,--out-implib,c:\ProjectII\qt-creator-win\bui
    ld\lib\qtcreator\plugins\Nokia\libTextEditor.a -o ..\..\..\lib\qtcreator\plugins
    \Nokia\TextEditor.dll object_script.TextEditor.Release -L"c:\Qt\2010.05\qt\lib"
    -LC:/ProjectII/qt-creator-win/build/lib/qtcreator -LC:/ProjectII/qt-creator-win
    /build/lib/qtcreator/plugins/Nokia -lUtils -lAggregation -lExtensionSystem -lBot
    an -lNet7ssh -lCore -lFind -lQtConcurrent -lLocator -LC:/ProjectII/qt-creator-wi
    n/src/plugins/texteditor/../../../lib/qtcreator/plugins/Nokia -lLogger -LC:/P
    rojectII/qt-creator-win/build/src/plugins/texteditor/../../../lib/qtcreator/plug
    ins/Nokia -lLogger -lQtXml4 -lQtGui4 -lQtCore4
    Creating library file: c:\ProjectII\qt-creator-win\build\lib\qtcreator\plugins\N
    okia\libTextEditor.a
    ./release\basetexteditor.o:basetexteditor.cpp.text+0x13cfc): undefined referen
    ce to `XMLProxy::XMLProxy(QString, QString, QString)'
    collect2: ld returned 1 exit status
    mingw32-make[4]: *** [..\..\..\lib\qtcreator\plugins\Nokia\TextEditor.dl l] Error
    1
    mingw32-make[4]: Leaving directory `C:/ProjectII/qt-creator-win/build/src/plugin
    s/texteditor'
    mingw32-make[3]: *** [release] Error 2
    mingw32-make[3]: Leaving directory `C:/ProjectII/qt-creator-win/build/src/plugin
    s/texteditor'
    mingw32-make[2]: *** [sub-texteditor-sub_Release] Error 2
    mingw32-make[2]: Leaving directory `C:/ProjectII/qt-creator-win/build/src/plugin
    s'
    mingw32-make[1]: *** [sub-plugins-sub_Release_ordered] Error 2
    mingw32-make[1]: Leaving directory `C:/ProjectII/qt-creator-win/build/src'
    mingw32-make: *** [sub-src-sub_Release_ordered] Error 2


    while this is my .pro file

    Qt Code:
    1. TEMPLATE = lib
    2. TARGET = Logger
    3. include(../../qtcreatorplugin.pri)
    4. DESTDIR = $$IDE_PLUGIN_PATH/Nokia
    5. PROVIDER = Nokia
    6. include(../../plugins/coreplugin/coreplugin.pri)
    7. HEADERS += LoggerPlugin.h \
    8. xmlproxy.h
    9. SOURCES += LoggerPlugin.cpp \
    10. xmlproxy.cpp
    11. OTHER_FILES += Logger.pluginspec
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "Undefined reference to" in QtCreator plugin

    I would have thought you'd get an undefined reference to XMLProxy::~XMLProxy()
    I can't see the function for that one.

  9. #9
    Join Date
    Nov 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: "Undefined reference to" in QtCreator plugin

    I put it actually in one of my tries but I still got the same error.
    But still if I move all the code into the .h file it works

  10. #10
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "Undefined reference to" in QtCreator plugin

    Maybe look at basetexteditor.h and its relation to XMLProxy.h
    You might need to add an INCLUDEPATH to your pro file to find it. if they are not side by side?


    Added after 30 minutes:


    OK, is the XMLProxy class built? can you see the .o file? Have you built that plugin/lib before you have linked to it?
    My guess is it is working when it is in your header file because it finds your header file, but if you haven't actually built an object to reference to then it won't find the function.
    Last edited by pan; 18th March 2011 at 14:12.

  11. #11
    Join Date
    Nov 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: "Undefined reference to" in QtCreator plugin

    Indeed the only .o file I can see is LoggerPlugin.o in C:\ProjectII\qt-creator-win\build\src\plugins\Logger directory
    The noob question is: How to proceed now?

  12. #12
    Join Date
    Nov 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: "Undefined reference to" in QtCreator plugin

    still can't get it to work, any help?

Similar Threads

  1. Replies: 2
    Last Post: 27th August 2011, 12:59
  2. Replies: 1
    Last Post: 19th February 2011, 13:32
  3. Replies: 2
    Last Post: 23rd June 2010, 22:00
  4. "Undefined reference to" error
    By f.tristano in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2009, 10:00
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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.