Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. undefined reference to qt_static _plugin
Forum Update on Monday, May 27th 2025

undefined reference to qt_static _plugin

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt 5.5staticplugin
14 Posts 3 Posters 5.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N NIXIN
    3 Jan 2019, 11:34

    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"

    static_plugin_qmake.pro

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

    interface.h

    #ifndef INTERFACE_H
    #define INTERFACE_H
    
    #include <QtPlugin>
    
    class Interface
    {
    public:
        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
    

    main.cpp

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

    plugin_qmake.pro

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

    pluginqmake.h

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

    pluginqmake.cpp

    #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.....

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 3 Jan 2019, 11:55 last edited by
    #2

    @NIXIN I think you forgot "QTPLUGIN += " in your pro file as described here: http://doc.qt.io/qt-5/plugins-howto.html#static-plugins

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    N 1 Reply Last reply 3 Jan 2019, 11:57
    0
    • J jsulm
      3 Jan 2019, 11:55

      @NIXIN I think you forgot "QTPLUGIN += " in your pro file as described here: http://doc.qt.io/qt-5/plugins-howto.html#static-plugins

      N Offline
      N Offline
      NIXIN
      wrote on 3 Jan 2019, 11:57 last edited by
      #3

      @jsulm what should I add with QTPLUGIN +=

      because I am creating my own plugin

      J 1 Reply Last reply 3 Jan 2019, 12:02
      0
      • N NIXIN
        3 Jan 2019, 11:57

        @jsulm what should I add with QTPLUGIN +=

        because I am creating my own plugin

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 3 Jan 2019, 12:02 last edited by jsulm 1 Mar 2019, 12:03
        #4

        @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 http://doc.qt.io/qt-5/qtwidgets-tools-plugandpaint-app-example.html

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        N 1 Reply Last reply 3 Jan 2019, 12:05
        0
        • J jsulm
          3 Jan 2019, 12:02

          @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 http://doc.qt.io/qt-5/qtwidgets-tools-plugandpaint-app-example.html

          N Offline
          N Offline
          NIXIN
          wrote on 3 Jan 2019, 12:05 last edited by NIXIN 1 Mar 2019, 12:06
          #5

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

          J 1 Reply Last reply 3 Jan 2019, 12:15
          0
          • N NIXIN
            3 Jan 2019, 12:05

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

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 3 Jan 2019, 12:15 last edited by
            #6

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

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            N 1 Reply Last reply 3 Jan 2019, 12:16
            0
            • J jsulm
              3 Jan 2019, 12:15

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

              N Offline
              N Offline
              NIXIN
              wrote on 3 Jan 2019, 12:16 last edited by
              #7

              @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
              
              J 1 Reply Last reply 3 Jan 2019, 12:18
              0
              • N NIXIN
                3 Jan 2019, 12:16

                @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
                
                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 3 Jan 2019, 12:18 last edited by
                #8

                @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).

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                N 1 Reply Last reply 3 Jan 2019, 12:21
                0
                • J jsulm
                  3 Jan 2019, 12:18

                  @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).

                  N Offline
                  N Offline
                  NIXIN
                  wrote on 3 Jan 2019, 12:21 last edited by
                  #9

                  @jsulm I tried same thing with this example http://doc.qt.io/qt-5/qtwidgets-tools-plugandpaint-app-example.html 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

                  J 1 Reply Last reply 3 Jan 2019, 12:24
                  0
                  • N NIXIN
                    3 Jan 2019, 12:21

                    @jsulm I tried same thing with this example http://doc.qt.io/qt-5/qtwidgets-tools-plugandpaint-app-example.html 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

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 3 Jan 2019, 12:24 last edited by
                    #10

                    @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?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    N 1 Reply Last reply 3 Jan 2019, 12:27
                    0
                    • J jsulm
                      3 Jan 2019, 12:24

                      @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?

                      N Offline
                      N Offline
                      NIXIN
                      wrote on 3 Jan 2019, 12:27 last edited by
                      #11

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

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        NIXIN
                        wrote on 4 Jan 2019, 09:52 last edited by
                        #12

                        can anybody help me with this issue??

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          NIXIN
                          wrote on 4 Jan 2019, 10:50 last edited by
                          #13

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

                          Q_IMPORT_PLUGIN(plugin_qmake)
                          

                          this line should have the class name of plugin

                          Q_IMPORT_PLUGIN(PluginQmake)
                          

                          now it works fine....

                          1 Reply Last reply
                          2
                          • N Offline
                            N Offline
                            Ni.Sumi
                            wrote on 4 Jan 2019, 15:09 last edited by
                            #14

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

                            1 Reply Last reply
                            1

                            11/14

                            3 Jan 2019, 12:27

                            • Login

                            • Login or register to search.
                            11 out of 14
                            • First post
                              11/14
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved