我正在创建Qt5应用程序的cmake项目。现在,当我在Clion中使用cmake编译我的应用程序时,我遇到了致命的错误。
我的CMakeLists.txt文件如下:
cmake_minimum_required(VERSION 2.8.11)
project(Oefening11_kv)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set (CMAKE_PREFIX_PATH C:\\Qt\\Qt5.8.0\\5.8\\mingw53_32\\lib\\cmake\\)
# Find the Qt libraries
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets)
find_package(Qt5Gui)
find_package(Qt5Charts)
set(Oefening11_kv_SOURCES main.cpp oefening11a.cpp oefening11b.cpp oefening11c.cpp)
set(Oefening11_kv_HEADERS oefening11a.h oefening11b.h oefening11c.h)
set(Oefening11_kv_FORMS oefening11a.ui)
QT5_WRAP_CPP(Oefening11_kv_HEADERS_MOC ${Oefening11_kv_HEADERS})
QT5_WRAP_UI(Oefening11_kv_FORMS_HEADERS ${Oefening11_kv_FORMS})
add_library(Oefening11_kv_CONFIG ${Oefening11_kv_HEADERS_MOC} ${Oefening11_kv_FORMS_HEADERS})
QT5_USE_MODULES(Oefening11_kv_CONFIG Widgets)
add_executable(Oefening11_kv ${Oefening11_kv_SOURCES} ${Oefening11_kv_CONFIG})
QT5_USE_MODULES(Oefening11_kv Core Gui Widgets Charts)
编译应用程序时Clion正在编写的错误是:
oefening11a.cpp:21:未定义引用
__imp__ZN8QtCharts11QLineSeriesC1EP7QObject' oefening11a.cpp:26: undefined reference to
__ imp__ZN8QtCharts9QXYSeries6appendEdd' oefening11a.cpp:30:未定义引用__imp__ZN8QtCharts6QChartC1EP13QGraphicsItem6QFlagsIN2Qt10WindowTypeEE' oefening11a.cpp:31: undefined reference to
__ imp__ZN8QtCharts6QChart9addSeriesEPNS_15QAbstractSeriesE' oefening11a.cpp:32:未定义引用__imp__ZNK8QtCharts6QChart6legendEv' oefening11a.cpp:33: undefined reference to
__ imp__ZN8QtCharts6QChart8setTitleERK7QString' oefening11a.cpp:36:未定义引用__imp__ZN8QtCharts10QValueAxisC1EP7QObject' oefening11a.cpp:37: undefined reference to
__ imp__ZN8QtCharts10QValueAxis14setLabelFormatERK7QString' oefening11a.cpp:38:未定义引用__imp__ZN8QtCharts13QAbstractAxis12setTitleTextERK7QString' oefening11a.cpp:39: undefined reference to
__ imp__ZN8QtCharts6QChart7addAxisEPNS_13QAbstractAxisE6QFlagsIN2Qt13AlignmentFlagEE' oefening11a.cpp:40:未定义引用__imp__ZN8QtCharts15QAbstractSeries10attachAxisEPNS_13QAbstractAxisE' oefening11a.cpp:43: undefined reference to
__ imp__ZN8QtCharts10QValueAxisC1EP7QObject' oefening11a.cpp:44: 未定义的引用__imp__ZN8QtCharts10QValueAxis14setLabelFormatERK7QString' oefening11a.cpp:45: undefined reference to
__ imp__ZN8QtCharts13QAbstractAxis12setTitleTextERK7QString' oefening11a.cpp:46:未定义引用__imp__ZN8QtCharts6QChart7addAxisEPNS_13QAbstractAxisE6QFlagsIN2Qt13AlignmentFlagEE' oefening11a.cpp:47: undefined reference to
__ imp__ZN8QtCharts15QAbstractSeries10attachAxisEPNS_13QAbstractAxisE' oefening11a.cpp:50:未定义引用__imp__ZN8QtCharts10QChartViewC1EPNS_6QChartEP7QWidget' oefening11a.cpp:51: undefined reference to
__ imp__ZN13QGraphicsView13setRenderHintEN8QPainter10RenderHintEb' oefening11a.cpp:54:未定义引用__imp__ZN11QMainWindow16setCentralWidgetEP7QWidget' oefening11a.cpp:73: undefined reference to
__ imp__ZN10QStatusBar11showMessageERK7QStringi' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x38): 未定义引用QMainWindow::event(QEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x40): undefined reference to
QObject :: eventFilter(QObject *,QEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x48): 对QObject::timerEvent(QTimerEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x50): undefined reference to
QObject :: childEvent(QChildEvent *)'的未定义引用 t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] +将0x58): 未定义引用QObject::customEvent(QEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x60): undefined reference to
QObject :: connectNotify(QMetaMethod const&)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x68)中: 未定义引用QObject::disconnectNotify(QMetaMethod const&)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x70): undefined reference to
QWidget :: devType()const' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x78): 未定义引用QWidget::setVisible(bool)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x80): undefined reference to
QWidget :: sizeHint()const' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] +均为0x88): 未定义引用QWidget::minimumSizeHint() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x90): undefined reference to
QWidget :: heightForWidth(int)const' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] 0x98在全局+): 未定义引用QWidget::hasHeightForWidth() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xa0): undefined reference to
QWidget :: paintEngine()const' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0xa8): 未定义引用QWidget::mousePressEvent(QMouseEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xb0): undefined reference to
QWidget :: mouseReleaseEvent(QMouseEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0xb8): 未定义引用QWidget::mouseDoubleClickEvent(QMouseEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xc0): undefined reference to
QWidget :: mouseMoveEvent(QMouseEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0xc8): 未定义引用QWidget::wheelEvent(QWheelEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xd0): undefined reference to
QWidget :: keyPressEvent(QKeyEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0xd8): 未定义引用QWidget::keyReleaseEvent(QKeyEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xe0): undefined reference to
QWidget :: focusInEvent(QFocusEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0xe8): 未定义引用QWidget::focusOutEvent(QFocusEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xf0): undefined reference to
QWidget :: enterEvent(QEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0xF8的): 未定义引用QWidget::leaveEvent(QEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x100): undefined reference to
QWidget :: paintEvent(QPaintEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] +量0x108): 未定义引用QWidget::moveEvent(QMoveEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x110): undefined reference to
QWidget :: resizeEvent(QResizeEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] +量0x118): 未定义引用QWidget::closeEvent(QCloseEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x120): undefined reference to
QMainWindow :: contextMenuEvent(QContextMenuEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0×128): 未定义引用QWidget::tabletEvent(QTabletEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x130): undefined reference to
QWidget :: actionEvent(QActionEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x138): 未定义引用QWidget::dragEnterEvent(QDragEnterEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x140): undefined reference to
QWidget :: dragMoveEvent(QDragMoveEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x148): 未定义引用QWidget::dragLeaveEvent(QDragLeaveEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x150): undefined reference to
QWidget :: dropEvent(QDropEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x158): 未定义引用QWidget::showEvent(QShowEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x160): undefined reference to
QWidget :: hideEvent(QHideEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x168): 未定义引用QWidget::nativeEvent(QByteArray const&, void*, long*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x170): undefined reference to
QWidget :: changeEvent(QEvent *)' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x178): 未定义的引用QWidget::metric(QPaintDevice::PaintDeviceMetric) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x180): undefined reference to
QWidget :: initPainter(QPainter *)const' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x188): 未定义引用QWidget::redirected(QPoint*) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x190): undefined reference to
QWidget :: sharedPainter()const' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x198): 未定义引用QWidget::inputMethodEvent(QInputMethodEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1a0): undefined reference to
QWidget :: inputMethodQuery(Qt :: InputMethodQuery)const' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x1a8): 未定义引用QWidget::focusNextPrevChild(bool)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1b0): undefined reference to
QMainWindow :: createPopupMenu()' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x1d8): 对{QWidget :: paintEngine()的non-virtual thunk to QWidget::devType() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1e0): undefined reference to
非虚拟thunk的未定义引用 常量' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x1e8): 对non-virtual thunk to QWidget::metric(QPaintDevice::PaintDeviceMetric) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1f0): undefined reference to
非虚拟thunk的未定义引用 QWidget :: initPainter(QPainter *)const' t_automoc.cpp :( RDATA $ _ZTV11Oefening11A [_ZTV11Oefening11A] + 0x1f8): 对{QWidget :: sharedPainter()的non-virtual thunk to QWidget::redirected(QPoint*) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x200): undefined reference to
非虚拟thunk的未定义引用 常量'
无法在我的cmake文件中找到问题。有人可以帮我这个吗?
答案 0 :(得分:0)
除了moc
,您还需要运行uic
:
set(CMAKE_AUTOUIC ON)
答案 1 :(得分:0)
好的,我发现了这个问题。我在x86 QT5库上使用x64编译器。将编译器更改为x86时,它会编译。