Search code examples
c++qtqwt

Unresolved external symbol: QMetaObject const QwtPlotMagnifier::staticMetaObject


I have a library that uses QwtPlotMagnifier, amongst other Qwt classes. I decided to subclass QwtPlotMagnifier so that I can emit a signal when the plot is rescaled. The library (mylib.lib) compiles, but the application using it is now complaining about an unresolved external related to the moc output of QwtPlotMagnifier.

I am linking qwt statically; so the requirement to have the preprocessor directive QWT_DLL in the lowest level library doesn't apply here.

Here's the error (the subclass is called PlotMagnifier):

mylib.lib(moc_PlotMagnifier.obj) : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QwtPlotMagnifier::staticMetaObject" (?staticMetaObject@QwtPlotMagnifier@@2UQMetaObject@@B)

Nothing special about the subclass declaration:

#pragma once

#include "qwt_plot_magnifier.h"
/**
subclass of QwtPlotMagnifier to provide a signal when zooming is complete
*/
class PlotMagnifier : public QwtPlotMagnifier
{
    Q_OBJECT
public:
  explicit PlotMagnifier(QWidget *w);
  virtual ~PlotMagnifier();
signals:
  void rescaled();
protected:
  virtual void rescale(double factor);  
};

I'm on visual studio 2013 fwiw. My application still includes qwtd.lib as it always has. This has got to be a stupid mistake on my part.. kickstart my brain please, someone!


Solution

  • Add this line to .pro file to give the compiler a hint for an external symbol:

    DEFINES += QWT_DLL
    

    In the file qwt_global.h have the macro. Without this macro, the compiler will think this is an internal symbol.