【问题标题】:Undefined reference error on QQuickWindow from cmake来自cmake的QQuickWindow上未定义的引用错误
【发布时间】:2016-07-01 23:03:30
【问题描述】:

我正在将 catkin 项目与 qt-quick 项目集成。 我做了一个粗犷的 CMakeLists.txt:

cmake_minimum_required (VERSION 2.8)
project (qml_ros_camera)

set(CMAKE_AUTOMOC ON)

find_package(Qt5Core REQUIRED)

set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage")

# set up a mapping so that the Release configuration for the Qt imported target is
# used in the COVERAGE CMake configuration.
set_target_properties(Qt5::Core PROPERTIES MAP_IMPORTED_CONFIG_COVERAGE "RELEASE")

get_target_property(QtCore_location Qt5::Core LOCATION)

find_package(Qt5 COMPONENTS Quick Core Network)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Declarative)

catkin_package()

include_directories(include ${OpenCV_INCLUDE_DIRS})

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(HEADER_FILES ~/image_transport_ws/src/qml_ros_camera/src/videoplayer.h)
set(SOURCE_FILES ~/image_transport_ws/src/qml_ros_camera/src/main.cpp
    ~/image_transport_ws/src/qml_ros_camera/src/videoplayer.cpp
    )

set(qml_ros_camera_RESOURCES qml.qrc)
qt5_add_resources(qml_ros_camera_RESOURCES_RCC ${qml_ros_camera_RESOURCES})

add_executable(qml_ros_camera
    ${SOURCE_FILES}
    ${qml_ros_camera_RESOURCES_RCC})

target_link_libraries(qml_ros_camera ${Qt5Widgets_LIBRARIES}
    ${Qt5Core}
    ${Qt5Declarative_LIBRARIES}
    ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})

include_directories(
    ~/image_transport_ws/src/qml_ros_camera/src/
    /opt/Qt/5.5/gcc_64/include/QtQuick
    /opt/Qt/5.5/gcc_64/include/QtCore
    ${Qt5Declarative_INCLUDE_DIRS}
    ${Qt5Widgets_INCLUDE_DIRS})

include_directories(${Qt5Widgets_INCLUDE_DIRS})

add_definitions(${Qt5Widgets_DEFINITIONS})

ADD_DEFINITIONS(${QT_DEFINITIONS})
qt5_use_modules(qml_ros_camera Widgets Qml)

我遇到的编译错误:

CMakeFiles/qml_ros_camera.dir/src/main.cpp.o: 
In function `QQuickWindow* qobject_cast<QQuickWindow*>(QObject*)': main.cpp:
(.text._Z12qobject_castIP12QQuickWindowET_P7QObject
[_Z12qobject_castIP12QQuickWindowET_P7QObject]+0x16)
: undefined reference to `QQuickWindow::staticMetaObject'

我正在使用 Qt-creator 和 C++。这个问题与我对 CMakeLists.txt 工作原理的理解不足有关。我该如何解决这个可怕的编译错误?

【问题讨论】:

    标签: compiler-errors cmake qml undefined-reference catkin


    【解决方案1】:

    尝试这样的链接:

    target_link_libraries(...
        Qt5::Core
        Qt5::Quick
        ...
    

    而且对于 qt 的东西,你不需要 include_directories/add_definitions。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      • 1970-01-01
      相关资源
      最近更新 更多