c++ CMakeLists includeT Qt5::QML不起作用

np8igboo  于 2022-11-19  发布在  其他
关注(0)|答案(1)|浏览(206)

这是我的CMakelists.txt文件。

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})

当我尝试用catkin_make -Wno-dev --only-pkg-with-deps osm_map编译我的项目时,它似乎找到了QT的每个模块(我还测试了下面未显示的其他模块),但没有QML。错误消息:

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安装在我的系统上,路径为/usr/include/x86_64-linux-gnu/qt5/QtQml,包括必要的头文件。知道为什么我可以这样做吗?QT的find_package调用应该找到QT附带的所有库和头文件,也许这是QML工作不正常的部分?

vq8itlhq

vq8itlhq1#

问题出在你
find_package(Qt5 COMPONENTS Widgets REQUIRED)
这里你问CMake你想要Qt5的Widget组件,但是你告诉它与Qml链接,你没有要求。
应将其更改为以下内容:
find_package(Qt5 COMPONENTS Widgets Qml REQUIRED)

相关问题