2017-04-20 491 views
0

我正在创建Qt5应用程序的cmake项目。现在,当我在Clion中使用cmake编译我的应用程序时,我得到了一个致命错误。Qt5 cmake找不到UI的头文件

我的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) 

当我编译的应用程序,克利翁被trowing的错误是:

oefening11a.cpp:21:未定义参考 __imp__ZN8QtCharts11QLineSeriesC1EP7QObject' oefening11a.cpp:26: undefined reference to __imp__ZN8QtCharts9QXYSeries6appendEdd' oefening11a.cpp:30:undefined reference to __imp__ZN8QtCharts6QChartC1EP13QGraphicsItem6QFlagsIN2Qt10WindowTypeEE' oefening11a.cpp:31: undefined reference to __imp__ZN8QtCharts6QChart9addSeriesEPNS_15QAbstract SeriesE ' 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常量&)” 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): undefined reference to 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 $ _ZTV11Oefening1 1A [_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)常量 ' 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): 未定义参照non-virtual thunk to QWidget::devType() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1e0): undefined reference to非虚拟形实转换到QWidget的:: paintEngine() 常量” 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): 未定义的参考non-virtual thunk to QWidget::redirected(QPoint*) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x200): undefined reference to非虚形实转换到了QWidget :: sharedPainter()const的 ”

找不到我的cmake文件中的问题。有人可以帮我弄这个吗?

+0

您的CMakeLists.txt对我来说看起来很好。 'CMAKE_AUTOUIC'不是必需的。如果文件的名称为'ui_oefening11a.h',我会查看构建目录。 – oLen

回答

0

此外moc,你将需要运行uic还有:

set(CMAKE_AUTOUIC ON) 
+0

当我添加这个时,我得到了错误的未定义引用的分配。 – JimmyD

+0

究竟是什么错误? –

+0

在问题中添加了确切的错误。 – JimmyD

0

好吧,我发现这个问题。我在x86 QT5库上使用了x64编译器。将编译器更改为x86编译器时,它会进行编译。