Home > OS >  CMakeLists includeT Qt5::QML does not work
CMakeLists includeT Qt5::QML does not work

Time:11-19

This is my CMakelists.txt file.

cmake_minimum_required(VERSION 3.0.2)
project(osm_map)
find_package(catkin REQUIRED COMPONENTS rviz)

find_package(Qt5 COMPONENTS Widgets REQUIRED)
set(QT_LIBRARIES Qt5::Widgets Qt5::Qml)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(SRC_FILES
  src/core.cpp
)

add_library(${PROJECT_NAME} ${SRC_FILES})
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${catkin_LIBRARIES})

When I try to compile my project with catkin_make -Wno-dev --only-pkg-with-deps osm_map, it seems to find every module of QT (I also tested others not shown below) but not QML. Error message:

CMake Error at osm_map/CMakeLists.txt:53 (target_link_libraries):
  Target "osm_map" links to:

    Qt5::Qml

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

QT QML is installed on my system and the path /usr/include/x86_64-linux-gnu/qt5/QtQml and includes the necessary headers. And idea why I could do? The find_package call for QT is supposed to find all libaries and headers shipped with QT, maybe that is the part that is not working properly for QML?

CodePudding user response:

The problem is in your

find_package(Qt5 COMPONENTS Widgets REQUIRED)

here you asked CMake that you wanted the Widgets component of Qt5 but then you tell it to link with Qml which you did not ask for.

You should change this to the following:

find_package(Qt5 COMPONENTS Widgets Qml REQUIRED)

  • Related