From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.

undefined reference to qt_static _plugin

  • Hi,

    I am trying to load a static plugin in Qt for which I have tried the below code. My project name is "static_plugin_qmake".
    I am creating a static plugin called "plugin_qmake" and trying to load it through a application "launcher"

    TEMPLATE = subdirs
    SUBDIRS  = plugin_qmake \
    TEMPLATE = app
    QT      += widgets
    HEADERS  = interface.h
    SOURCES += main.cpp
    LIBS    += "/home/uidm9805/Qt Projects/static_plugin_qmake/build/plugin_qmake/libplugin_qmake.a"


    #ifndef INTERFACE_H
    #define INTERFACE_H
    #include <QtPlugin>
    class Interface
        virtual ~Interface() {}
        virtual void setValue(int value) = 0;
        virtual int getValue() = 0;
    #define Interface_iid "interface_identifier_id"
    Q_DECLARE_INTERFACE(Interface, Interface_iid)
    #endif // INTERFACE_H


    #include <QApplication>
    #include <QtPlugin>
    #include <QDebug>
    int main(int argc, char *argv[])
        QApplication app(argc, argv);
        qDebug() << "Hello World";
        return app.exec();

    TEMPLATE      = lib
    CONFIG       += plugin static
    QT           += widgets
    INCLUDEPATH  += ../..
    HEADERS       = pluginqmake.h
    SOURCES       = pluginqmake.cpp
    TARGET        = $$qtLibraryTarget(plugin_qmake)


    #ifndef PLUGINQMAKE_H
    #define PLUGINQMAKE_H
    #include <QObject>
    #include <QtPlugin>
    #include "../launcher/interface.h"
    class PluginQmake : public QObject,
                        public Interface
        Q_PLUGIN_METADATA(IID Interface_iid)
        void setValue(int value);
        int getValue();
        int mValue;
    #endif // PLUGINQMAKE_H


    #include "pluginqmake.h"
    void PluginQmake::setValue(int value)
        mValue = value;
    int PluginQmake::getValue()
        return mValue;

    But when I build this project, I get following errors:

    /home/uidm9805/Qt Projects/static_plugin_qmake/launcher/main.cpp:6: error: undefined reference to 'qt_static_plugin_plugin_qmake()'
    collect2: error: ld returned 1 exit status

    I don't understand why I am getting this error? I need help to make it work.....

  • Qt Champions 2018

    @NIXIN I think you forgot "QTPLUGIN += " in your pro file as described here:

  • @jsulm what should I add with QTPLUGIN +=

    because I am creating my own plugin

  • Qt Champions 2018

    @NIXIN Sorry, my post was wrong.
    "Link your application with your plugin library using LIBS in the .pro file." - so, using LIBS is correct. But you're using it wrongly, it should be:

    LIBS    += -L"/home/uidm9805/Qt Projects/static_plugin_qmake/build/plugin_qmake" -lplugin_qmake

    Better to use relative paths, see

  • @jsulm I tried using LIBS += the way you suggested, however still it is not working...
    getting same errors again

  • Qt Champions 2018

    @NIXIN Can you show your LIBS line from your pro file?

  • @jsulm

    TEMPLATE = app
    QT      += widgets
    HEADERS  = interface.h
    SOURCES += main.cpp
    #LIBS    += "/home/uidm9805/Qt Projects/static_plugin_qmake/build/plugin_qmake/libplugin_qmake.a"
    LIBS    += -L"/home/uidm9805/Qt Projects/static_plugin_qmake/build/plugin_qmake" -lplugin_qmake

  • Qt Champions 2018

    @NIXIN You should check the linker call as you have a space in your path which can cause issues (you should avoid spaces in paths).

  • @jsulm I tried same thing with this example and its working fine there

    LIBS += "/home/uidm9805/Qt Projects/plugandpaint/build/plugandpaint/plugins/libpnp_basictools.a"

    don't know why this project is behaving in odd manner

  • Qt Champions 2018

    @NIXIN Is your plug-in really located here: /home/uidm9805/Qt Projects/static_plugin_qmake/build/plugin_qmake? And was it build with exact same compiler and Qt version?

  • @jsulm yes plugin is located in the given path and compiler versions are same

  • can anybody help me with this issue??

  • After lot of hit and trial, I got the mistake I was doing


    this line should have the class name of plugin


    now it works fine....

  • If it's solved, Please set it to "Solved" from unsolved.

Log in to reply