LNK2001: Unresolved external symbol when using qwt plot in Qt creator

1.9k views Asked by At

I am subclassing QwtPlot. I have the following error:

moc_myplot.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const QwtPlot::staticMetaObject" (?staticMetaObject@QwtPlot@@2UQMetaObject@@B) I have tried to the following things: run qmake, rebuild, clean, delete debug folder, recompile qwt library. That doesn't help. Here is minimal code: myplot.h:

#ifndef MYPLOT_H
#define MYPLOT_H
#include <QObject>
#include <qwt_plot.h>

class MyPlot : public QwtPlot
{
    Q_OBJECT
public:
    MyPlot();
};

#endif // MYPLOT_H

myplot.cpp:

#include "myplot.h"

MyPlot::MyPlot()
{

}

Here is .pro file:

#-------------------------------------------------
#
# Project created by QtCreator 2015-06-22T19:33:24
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = MyPlot
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp \
    myplot.cpp

HEADERS  += mainwindow.h \
    myplot.h

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../qwt-6.1.2/lib/ -lqwt
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../qwt-6.1.2/lib/ -lqwtd
else:unix: LIBS += -L$$PWD/../../../../../qwt-6.1.2/lib/ -lqwt

INCLUDEPATH += $$PWD/../../../../../qwt-6.1.2/include
DEPENDPATH += $$PWD/../../../../../qwt-6.1.2/include

I am using Qt Creator 3.4.1 Based on Qt 5.4.2 (MSVC 2013, 32 bit). Kit: Desktop Qt 5.4.2 MSVC2013 64bit. Compiler: Microsof Visual C++ Compiler 12.0(amd64). If I comment Q_OBJECT macro in myplot.h everything is ok. I can use qwt_plot without subclassing, so that this->setCentralWidget(new QwtPlot()); line in mainwindow.cpp is ok.

1

There are 1 answers

1
Tyler Jandreau On BEST ANSWER

It seems this is an old issue that was present in at least version 4.6.

The workaround is basically a preprocessor define of QWT_DLL from the "very lowest library that calls QWT".