我正在为我的 Qt5 应用程序创建一个 cmake 项目。现在,当我在 Clion 中使用 cmake 编译应用程序时,出现了 fatal error 。
我的 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 抛出的错误是:
block 引用>oefening11a.cpp:21: undefined reference to
__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_15QAbstractSeriesE' oefening11a.cpp:32: undefined reference to__imp__ZNK8QtCharts6QChart6legendEv' oefening11a.cpp:33: undefined reference to
__imp__ZN8QtCharts6QChart8setTitleERK7QString' oefening11a.cpp:36: undefined reference to__imp__ZN8QtCharts10QValueAxisC1EP7QObject' oefening11a.cpp:37: undefined reference to
__imp__ZN8QtCharts10QValueAxis14setLabelFormatERK7QString' oefening11a.cpp:38: undefined reference to__imp__ZN8QtCharts13QAbstractAxis12setTitleTextERK7QString' oefening11a.cpp:39: undefined reference to
__imp__ZN8QtCharts6QChart7addAxisEPNS_13QAbstractAxisE6QFlagsIN2Qt13AlignmentFlagEE' oefening11a.cpp:40: undefined reference to__imp__ZN8QtCharts15QAbstractSeries10attachAxisEPNS_13QAbstractAxisE' oefening11a.cpp:43: undefined reference to
__imp__ZN8QtCharts10QValueAxisC1EP7QObject' oefening11a.cpp:44: undefined reference to__imp__ZN8QtCharts10QValueAxis14setLabelFormatERK7QString' oefening11a.cpp:45: undefined reference to
__imp__ZN8QtCharts13QAbstractAxis12setTitleTextERK7QString' oefening11a.cpp:46: undefined reference to__imp__ZN8QtCharts6QChart7addAxisEPNS_13QAbstractAxisE6QFlagsIN2Qt13AlignmentFlagEE' oefening11a.cpp:47: undefined reference to
__imp__ZN8QtCharts15QAbstractSeries10attachAxisEPNS_13QAbstractAxisE' oefening11a.cpp:50: undefined reference to__imp__ZN8QtCharts10QChartViewC1EPNS_6QChartEP7QWidget' oefening11a.cpp:51: undefined reference to
__imp__ZN13QGraphicsView13setRenderHintEN8QPainter10RenderHintEb' oefening11a.cpp:54: undefined reference to__imp__ZN11QMainWindow16setCentralWidgetEP7QWidget' oefening11a.cpp:73: undefined reference to
__imp__ZN10QStatusBar11showMessageERK7QStringi' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x38): undefined reference toQMainWindow::event(QEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x40): undefined reference to
QObject::eventFilter(QObject*, QEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x48): undefined reference toQObject::timerEvent(QTimerEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x50): undefined reference to
QObject::childEvent(QChildEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x58): undefined reference toQObject::customEvent(QEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x60): undefined reference to
QObject::connectNotify(QMetaMethod const&)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x68): undefined reference toQObject::disconnectNotify(QMetaMethod const&)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x70): undefined reference to
QWidget::devType() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x78): undefined reference toQWidget::setVisible(bool)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x80): undefined reference to
QWidget::sizeHint() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x88): undefined reference toQWidget::minimumSizeHint() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x90): undefined reference to
QWidget::heightForWidth(int) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x98): undefined reference toQWidget::hasHeightForWidth() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xa0): undefined reference to
QWidget::paintEngine() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xa8): undefined reference toQWidget::mousePressEvent(QMouseEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xb0): undefined reference to
QWidget::mouseReleaseEvent(QMouseEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xb8): undefined reference toQWidget::mouseDoubleClickEvent(QMouseEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xc0): undefined reference to
QWidget::mouseMoveEvent(QMouseEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xc8): undefined reference toQWidget::wheelEvent(QWheelEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xd0): undefined reference to
QWidget::keyPressEvent(QKeyEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xd8): undefined reference toQWidget::keyReleaseEvent(QKeyEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xe0): undefined reference to
QWidget::focusInEvent(QFocusEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xe8): undefined reference toQWidget::focusOutEvent(QFocusEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xf0): undefined reference to
QWidget::enterEvent(QEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xf8): undefined reference toQWidget::leaveEvent(QEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x100): undefined reference to
QWidget::paintEvent(QPaintEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x108): undefined reference toQWidget::moveEvent(QMoveEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x110): undefined reference to
QWidget::resizeEvent(QResizeEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x118): undefined reference toQWidget::closeEvent(QCloseEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x120): undefined reference to
QMainWindow::contextMenuEvent(QContextMenuEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x128): undefined reference toQWidget::tabletEvent(QTabletEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x130): undefined reference to
QWidget::actionEvent(QActionEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x138): undefined reference toQWidget::dragEnterEvent(QDragEnterEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x140): undefined reference to
QWidget::dragMoveEvent(QDragMoveEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x148): undefined reference toQWidget::dragLeaveEvent(QDragLeaveEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x150): undefined reference to
QWidget::dropEvent(QDropEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x158): undefined reference toQWidget::showEvent(QShowEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x160): undefined reference to
QWidget::hideEvent(QHideEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x168): undefined reference toQWidget::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): undefined reference toQWidget::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): undefined reference toQWidget::redirected(QPoint*) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x190): undefined reference to
QWidget::sharedPainter() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x198): undefined reference toQWidget::inputMethodEvent(QInputMethodEvent*)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1a0): undefined reference to
QWidget::inputMethodQuery(Qt::InputMethodQuery) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1a8): undefined reference toQWidget::focusNextPrevChild(bool)' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1b0): undefined reference to
QMainWindow::createPopupMenu()' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1d8): undefined reference tonon-virtual thunk to QWidget::devType() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1e0): undefined reference to
non-virtual thunk to QWidget::paintEngine() const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1e8): undefined reference tonon-virtual thunk to QWidget::metric(QPaintDevice::PaintDeviceMetric) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1f0): undefined reference to
non-virtual thunk to QWidget::initPainter(QPainter*) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1f8): undefined reference tonon-virtual thunk to QWidget::redirected(QPoint*) const' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x200): undefined reference to
non-virtual thunk to QWidget::sharedPainter() const'在我的 cmake 文件中找不到问题。有人可以帮我解决这个问题吗?
最佳答案
好的,我发现了这个问题。我在 x86 QT5 库上使用 x64 编译器。将编译器更改为 x86 时,它会进行编译。
关于cmake - Qt5 cmake找不到ui的头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43525049/