Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Own static linking plugin

I have plugin and i want static link it with my app. In plugin.pro file i have:

TEMPLATE = lib
CONFIG += staticlib

In plugin.cpp:

Q_EXPORT_PLUGIN2(plugin, pluginClass)

Of course TARGET in .pro file is the same as plugin name.

In myapp.pro file:

LIBS += libplugin.a

main.cpp:

#include <QtGui/QApplication>
#include <QtPlugin>

Q_IMPORT_PLUGIN(plugin)

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    ...
    return a.exec();
}

Plugin compiles without errors, i got *.a and *.o files, so i copied *.a file to myapp directory and when i trying compile i get error like this:

cannot find -lmyplugin.a
collect2: ld returned 1 exit status

So i gave full path to libplugin.a in myapp.pro file and i got in the line with Q_IMPORT_PLUGIN error:

undefined reference to `qt_plugin_instance_plugin()'

and much errors like this:

undefined reference to `pluginClass::function()'

I included *.h file of my plugin.

What am I doing wrong?

like image 435
Jan Nowak Avatar asked Sep 24 '26 23:09

Jan Nowak


1 Answers

In your plugin .pro file use this code:

CONFIG += plugin static

instead of

CONFIG += staticlib
like image 72
Vladimir Kolesnikov Avatar answered Sep 26 '26 16:09

Vladimir Kolesnikov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!