title: Qt Cannot load plugin : undefined symbol iPlugin::staticMetaObject
body: <p>I'm trying to have a plugin system in my qt program.</p>
  
  <p>Even if I think my code is good, I still have a linking error in the main program.
  I'm using <strong>QPluginLoader</strong> to load the plugin. The method <strong>instantiate</strong> returns a null pointer and the error string is :</p>
  
  <pre><code>Cannot load library *library* : (*library*: undefined symbol: _ZN7iPlugin16staticMetaObjectE)
  </code></pre>
  
  <p>Here is the interface iPlugin.h :</p>
  
  <pre><code>#ifndef IPLUGIN_H
  #define IPLUGIN_H
  
  #include &lt;QObject&gt;
  #include &lt;QtPlugin&gt;
  
  class QWidget;
  
  class iPlugin : public QObject
  {
      Q_OBJECT
  
  public:
      virtual ~iPlugin() {}
      virtual const QString &amp;getName() const = 0;
      virtual QWidget *onStart() = 0;
  
  public slots:
      virtual void onMenu() = 0;
  };
  Q_DECLARE_INTERFACE(iPlugin, "Project.iPlugin")
  
  #endif // IPLUGIN_H
  </code></pre>
  
  <p>The plugin file textplugin.h</p>
  
  <pre><code>#ifndef TEXTPLUGIN_H
  #define TEXTPLUGIN_H
  
  #include &lt;QObject&gt;
  
  #include "iplugin.h"
  
  class QString;
  
  class TextPlugin : public iPlugin
  {
      Q_OBJECT
      Q_INTERFACES(iPlugin)
  
  public:
      TextPlugin();
      virtual ~TextPlugin();
      const QString &amp;getName() const;
      QWidget *onStart();
  
  public slots:
      void onMenu();
  
  private:
      const QString _name;
  };
  
  #endif // TEXTPLUGIN_H
  </code></pre>
  
  <p>And the plugin file textplugin.cpp :</p>
  
  <pre><code>#include &lt;QString&gt;
  
  #include "textplugin.h"
  #include "textwidget.h"
  
  #include &lt;iostream&gt;
  
  TextPlugin::TextPlugin() :
      _name("text")
  {
      std::cout &lt;&lt; "Hello" &lt;&lt; std::endl;
  }
  
  TextPlugin::~TextPlugin()
  {
  }
  
  const QString &amp;TextPlugin::getName() const
  {
      return (this-&gt;_name);
  }
  
  QWidget *TextPlugin::onStart()
  {
      return (new TextWidget);
  }
  
  void TextPlugin::onMenu()
  {
  
  }
  
  Q_EXPORT_PLUGIN2(plug_text, TextPlugin)
  </code></pre>
  
  <p>Does anyone have an idea ?
  I'm stuck on it for about 6 hours, I'm going crazy.</p>
  
  <p>Thanks in advance</p>
  
  <p>EDIT : I moved on Qt5, using <strong>Q_PLUGIN_METADATA(IID "Project.plug_text")</strong> in my class declaration and deleting <strong>Q_EXPORT_PLUGIN2(plug_text, TextPlugin)</strong> of the cpp file but nothing have changed, the error is the same.</p>
  
  <p>EDIT2 : I have forgotten the <strong>QPluginLoader</strong> code, here it is :</p>
  
  <pre><code>QPluginLoader loader("/home/bambou/build-TestPlugin-Desktop-Debug/plugin/libplug_text.so");
  if (QObject *obj = loader.instance()) {
      std::cout &lt;&lt; "hello !" &lt;&lt; std::endl;
      iPlugin *plugin = qobject_cast&lt;iPlugin *&gt;(obj);
      this-&gt;registerPlugin(file, plugin);
  } else {
      std::cout &lt;&lt; loader.errorString().toStdString() &lt;&lt; std::endl;
  }
  </code></pre>