2

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!

Darkmoor
  • 862
  • 11
  • 29
mike
  • 1,192
  • 9
  • 32

2 Answers2

1

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.

Crawl.W
  • 403
  • 5
  • 17
mohabouje
  • 3,867
  • 2
  • 14
  • 28
  • I thought I had addressed both of those points above - I'm using MSVC to compile, so I have no CONFIG to setup (and I'm already succesfully using QWT throughout). Also I'm linking qwt statically, so I don't need QWT_DLL; in fact if I define this, I get errors all over the place – mike Mar 20 '17 at 11:51
  • 2
    I take it back! After cleaning and rebuilding, I can compile just fine with QWT_DLL. This solves the problem, many thanks! – mike Mar 20 '17 at 12:30
0

Check, if you have all needed includes in you Visual Studio project.

C/C++ / Additional Include Directories
Here should be a path to <qwt_dir\include> be

Linker / General / Additional Library Directories
Here should be a path to <qwt_dir\lib> be

Linker / Input
Should include qwtd.lib (for debug configuration) and qwt.lib (for release)

Also, check that you have those entries in Release and Debug configurations, it is easy to configure only Debug, while working on Release configuration.

Also, check that you have moc_* file (something like moc_plotmagnifier.cpp) for your PlotMagnifier under Generated Files in your project view, sometimes Qt addin fails to add them.

Dmitriy
  • 515
  • 7
  • 14