[Interest] Link Errors when Creating a Windows DLL containing Qt Widgets

Mike Jackson imikejackson at gmail.com
Mon May 14 16:35:44 CEST 2012


I am trying to create a shared library for a part of my project that
contains a class derived from QFrame called QFilterWidget. If I build
the code as a shared library I am getting link errors with the
following output.

19>QLeeMarchingCubesWidget.obj : error LNK2001: unresolved external
symbol "public: static struct QMetaObject const
QFilterWidget::staticMetaObject"
(?staticMetaObject at QFilterWidget@@2UQMetaObject@@B)
19>QSMVtkPolyDataWriterWidget.obj : error LNK2001: unresolved external
symbol "public: static struct QMetaObject const
QFilterWidget::staticMetaObject"
(?staticMetaObject at QFilterWidget@@2UQMetaObject@@B)

I am running moc on the class which generates my moc_QFilterWidget.cxx
file and I have the necessary __declspec(dllexport)/(dllimport) stuff
defined in another header.

  #if defined (PipelineBuilderLib_EXPORTS)  /* Compiling the DLL/Dylib */
    #if defined (_MSC_VER)  /* MSVC Compiler Case */
      #define  PipelineBuilderLib_EXPORT __declspec(dllexport)
    #elif (__GNUC__ >= 4)  /* GCC 4.x has support for visibility options */
      #define PipelineBuilderLib_EXPORT __attribute__ ((visibility("default")))
    #endif
  #else  /* Importing the DLL into another project */
    #if defined (_MSC_VER)  /* MSVC Compiler Case */
      #define  PipelineBuilderLib_EXPORT __declspec(dllimport)
    #elif (__GNUC__ >= 4)  /* GCC 4.x has support for visibility options */
      #define PipelineBuilderLib_EXPORT __attribute__ ((visibility("default")))
    #endif
  #endif


This is the top part of the class declaration for QFilterWidget:
class PipelineBuilderLib_EXPORT QFilterWidget : public QGroupBox
{
    Q_OBJECT;
  public:
    QFilterWidget(QWidget* parent = NULL);
    virtual ~QFilterWidget();
....

};

The link errors occur when I am creating a plugin library
(SurfaceMeshPlugin) which uses the library that the QFilterWidget is
compiled into (PipelineLib). I'm not really sure what I am missing at
this point. I am mostly an OS X guy so I may just be missing something
about building Qt based DLL's on windows. Building as a static library
is NOT possible because of a singleton class that is in the
PipelineLib. If I build as a static library then I get 2 distinct
instances of a "singleton" which is odd but understandable if the
plugin links a static lib and the Application links a static lib.

If anyone might be able to shed some light on how to create a DLL that
has QtWidgets with their signals/slots that would be awesome.

Thanks
-- 
Mike Jackson
imikejackson _at_ gee-mail dot com



More information about the Interest mailing list