LNK2001:在 Qt creator 中使用 qwt plot 时无法解析的外部符号
LNK2001: Unresolved external symbol when using qwt plot in Qt creator
我正在子类化 QwtPlot。我有以下错误:
moc_myplot.obj:-1: 错误: LNK2001: 未解析的外部符号 "public: static struct QMetaObject const QwtPlot::staticMetaObject" (?staticMetaObject@QwtPlot@@2UQMetaObject@@B)
我尝试了以下操作:运行 qmake、重建、清理、删除调试文件夹、重新编译 qwt 库。那没有帮助。这是最少的代码:
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()
{
}
这里是 .pro 文件:
#-------------------------------------------------
#
# 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
我正在使用基于 Qt 5.4.2(MSVC 2013,32 位)的 Qt Creator 3.4.1。工具包:桌面 Qt 5.4.2 MSVC2013 64 位。编译器:Microsoft Visual C++ 编译器 12.0(amd64)。如果我在 myplot.h
中注释 Q_OBJECT
宏,一切正常。我可以在没有子类化的情况下使用 qwt_plot
,这样 mainwindow.cpp
中的 this->setCentralWidget(new QwtPlot());
行就可以了。
这似乎是一个旧的 issue,至少在 4.6 版中就有。
解决方法基本上是 "very lowest library that calls QWT" 中 QWT_DLL
的预处理器定义。
我正在子类化 QwtPlot。我有以下错误:
moc_myplot.obj:-1: 错误: LNK2001: 未解析的外部符号 "public: static struct QMetaObject const QwtPlot::staticMetaObject" (?staticMetaObject@QwtPlot@@2UQMetaObject@@B) 我尝试了以下操作:运行 qmake、重建、清理、删除调试文件夹、重新编译 qwt 库。那没有帮助。这是最少的代码: 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()
{
}
这里是 .pro 文件:
#-------------------------------------------------
#
# 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
我正在使用基于 Qt 5.4.2(MSVC 2013,32 位)的 Qt Creator 3.4.1。工具包:桌面 Qt 5.4.2 MSVC2013 64 位。编译器:Microsoft Visual C++ 编译器 12.0(amd64)。如果我在 myplot.h
中注释 Q_OBJECT
宏,一切正常。我可以在没有子类化的情况下使用 qwt_plot
,这样 mainwindow.cpp
中的 this->setCentralWidget(new QwtPlot());
行就可以了。
这似乎是一个旧的 issue,至少在 4.6 版中就有。
解决方法基本上是 "very lowest library that calls QWT" 中 QWT_DLL
的预处理器定义。