PDA

View Full Version : "Undefined reference to" in QtCreator plugin



davif
17th March 2011, 13:37
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

Gokulnathvc
17th March 2011, 13:39
#include <Logger.h>
#include <qlog/qlog.h>

Included??

davif
17th March 2011, 13:43
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

davif
17th March 2011, 19:19
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?

stampede
17th March 2011, 19:35
Show the code, it's almost impossible to help without seeing it.

davif
18th March 2011, 09:16
LoggerPlugin.h

#ifndef LOGGERPLUGIN_H
#define LOGGERPLUGIN_H
#include <QTextStream>
#include <QtPlugin>
#include <QStringList>
#include <QMessageBox>
#include <QString>
#include <QtCore/QDebug>
#include <Logger/xmlproxy.h>




class LoggerPlugin : public ExtensionSystem::IPlugin
{

private:
QString lookupName(int id);
int lookupID(QString name);

public:

XMLLoggerPlugin();
~XMLLoggerPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();

// this is the method called by CppEditor. It just instantiate my proxy object.
static void register(QString name, QString filename, QString type){
XMLProxy pr(name, filename, type);
}
};
#endif // LOGGERPLUGIN_H


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

XMLProxy.h


#ifndef XMLPROXY_H
#define XMLPROXY_H
class XMLProxy
{
public:
XMLProxy();
~XMLProxy();
XMLProxy(QString name, QString filename, QString type);
void serializeXML();
QString _name, _filename, _type;
};

#endif // XMLPROXY_H

and the class implementation
XMLProxy.cpp

#include <QDateTime>
#include <QFile>
#include <QXmlStreamWriter>
#include <QDate>
#include <extensionsystem/iplugin.h>
#include <QtXml/QDomDocument>
#include <QtXml/QDomElement>
#include <QtXml/QDomText>
#include "xmlproxy.h"
XMLProxy::XMLProxy(){}
XMLProxy::XMLProxy(QString name, QString filename, QString type){
this->_name=name;
this->_filename=namefilename;
this->_type=type;
}

XMLProxy::serializeXML(){
//stub of the method to serialize a XMLProxy to a XML file
QFile file("Logfile.xml");
QDomDocument doc("Events");
QDomElement ev = doc.createElement("event");
QDomElement typeNode = doc.createElement("type");
QDomText typeTxt = doc.createTextNode(this->_type);
typeNode.appendChild(typeTxt);
ev.appendChild(typeNode);
//...to be cont´d
}

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

davif
18th March 2011, 13:14
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


TEMPLATE = lib
TARGET = Logger
include(../../qtcreatorplugin.pri)
DESTDIR = $$IDE_PLUGIN_PATH/Nokia
PROVIDER = Nokia
include(../../plugins/coreplugin/coreplugin.pri)
HEADERS += LoggerPlugin.h \
xmlproxy.h
SOURCES += LoggerPlugin.cpp \
xmlproxy.cpp
OTHER_FILES += Logger.pluginspec

pan
18th March 2011, 13:32
I would have thought you'd get an undefined reference to XMLProxy::~XMLProxy()
I can't see the function for that one.

davif
18th March 2011, 13:40
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 :confused:

pan
18th March 2011, 14:12
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.

davif
18th March 2011, 14:21
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?

davif
20th March 2011, 08:38
still can't get it to work, any help?