"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
Re: "Undefined reference to" in QtCreator plugin
#include <Logger.h>
#include <qlog/qlog.h>
Included??
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
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?
Re: "Undefined reference to" in QtCreator plugin
Show the code, it's almost impossible to help without seeing it.
Re: "Undefined reference to" in QtCreator plugin
LoggerPlugin.h
Code:
#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:
public:
XMLLoggerPlugin();
~XMLLoggerPlugin();
void extensionsInitialized();
void shutdown();
// this is the method called by CppEditor. It just instantiate my proxy object.
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
Code:
#ifndef XMLPROXY_H
#define XMLPROXY_H
class XMLProxy
{
public:
XMLProxy();
~XMLProxy();
void serializeXML();
};
#endif // XMLPROXY_H
and the class implementation
XMLProxy.cpp
Code:
#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(){}
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");
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
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
Code:
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
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.
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 :confused:
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.
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?
Re: "Undefined reference to" in QtCreator plugin
still can't get it to work, any help?