C++ Qt: can't find methods of dynamic library -
i'm working on application in qt has plug-able. i've looked around while , came upon example plugins in qt: http://doc.qt.digia.com/4.6/tools-echoplugin.html
i've changed little classes. i've added random number generator:
randomgenerator.h:
#ifndef randomnumber_h #define randomnumber_h class randomnumber { public: ~randomnumber(); randomnumber(); int getnumber(); }; #endif // randomnumber_h
randomgenerator.cpp:
#include "randomnumber.h" #include <stdio.h> #include <stdlib.h> #include <time.h> randomnumber::randomnumber() { srand(time(null)); } int randomnumber::getnumber(){ return rand() % 20; }
then made small adjustment in plugin:
echoplugin.cpp:
#include <qtgui> #include "randomnumber.h" #include "echoplugin.h" qstring echoplugin::echo(const qstring &message) { randomnumber* rn = new randomnumber(); qstring a; a.setnum(rn->getnumber()); return a; } q_export_plugin2(echoplugin, echoplugin);
it's simplified version of program i'm working on. other classes , methods of example on given link haven't been altered. when try execute program, same error have own program:
/home/user/qt/v1/echoplugin/echoplugin: symbol lookup error: /home/user/qt/v1/echoplugin/plugins/libechoplugin.so: undefined symbol: _zn12randomnumberc1ev
i ran through c++filt, , said problem lies with
randomnumber::randomnumber()
but can't find error concerning method.
thanks in advance!
edit: time, i've solved problem myself , give explanation programmers encounter same problem.
it's simple solution: if want use code of headers , sourcefiles not in headerfile of interface, have include relative path in .pro-file, , includes both source-files , headerfiles. if wanted use randomnumber class, i'd have add .pro-file of plugin:
headers += ../randomnumber.h sources += ../randomnumber.cpp