我想在Cmake
中使用Ubuntu
创建一个项目。
我的CMakeList
是:
cmake_minimum_required(VERSION 2.8.3)
project(client_ros)
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
qt_build
)
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
FOLLOW_SYMLINKS src/*.cpp include/client_ros/*.hpp
include/client_ros/*.h)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
resources/*.qrc)
include_directories(include ${catkin_INCLUDE_DIRS})
#################################
find_package(Qt5Core REQUIRED)
find_package(Qt5Sql REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5Multimedia REQUIRED)
find_package(Qt5Qml REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
#set configs
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
QT5_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT5_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT5_WRAP_CPP(QT_MOC_HPP ${QT_MOC})
include_directories(
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Quick_INCLUDE_DIRS}
${Qt5QuickControls2_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5PrintSupport_INCLUDE_DIRS}
${Qt5Qml_INCLUDE_DIRS}
# ./src
${Qt5Sql_INCLUDE_DIRS}
${Qt5Charts_INCLUDE_DIRS}
${Qt5Multimedia_INCLUDE_DIRS}
${QT_INCLUDE_DIR}
)
add_definitions( -std=c++11 -fPIC)
add_definitions(${Qt5Widgets_DEFINITIONS} ${QtQml_DEFINITIONS}
${${Qt5Quick_DEFINITIONS}})
catkin_package(
INCLUDE_DIRS
include
CATKIN_DEPENDS
std_msgs
roscpp
)
include_directories(include)
include_directories(${catkin_INCLUDE_DIRS})
include_directories(${Eigen_INCLUDE_DIRS})
add_executable(client_ros_node src/client_ros_node.cpp
src/clientclass.cpp
include/client_ros/clientclass.h
${coreheaders}
${corecpps}
)
#qt5_use_modules(gui Quick Core)
add_library(${PROJECT_NAME}
${QT_SOURCES}
${QT_MOC_HPP}
${QT_RESOURCES_CPP}
${QT_MOC}
${QT_UI_H}
)
target_link_libraries(client_ros_node ${catkin_LIBRARIES})
target_link_libraries(client_ros_node
Qt5::Core
Qt5::Widgets
Qt5::Quick
Qt5::Sql
Qt5::Multimedia
)
add_dependencies(client_ros_node
client_ros_generate_messages_cpp_qt_build)
qt5_add_resources(qml_QRC resources/qml.qrc)
qt5_use_modules(client_ros_node Quick Gui Core Widgets)
## Mark cpp header files for installation
install(DIRECTORY include/client_ros/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)
我收到以下错误:
QQmlApplicationEngine无法加载组件 文件:///home/amir/work_space/build/client_ros/devel/lib/client_ros/main.qml:1 模块" QtQuick"版本2.9未安装
当我添加find_package(Qt5QuickControls2 REQUIRED)
时,我收到以下错误:
/home/amir/work_space/src/client_ros/CMakeLists.txt:19:错误:不是 提供" FindQt5QuickControls2.cmake"在CMAKE_MODULE_PATH这个 项目已要求CMake查找提供的包配置文件 by" Qt5QuickControls2",但是CMake没找到。找不到了 包装配置文件由" Qt5QuickControls2"提供。任何一个 以下名称:Qt5QuickControls2Config.cmake qt5quickcontrols2-config.cmake添加安装前缀 " Qt5QuickControls2"到CMAKE_PREFIX_PATH或设置 " Qt5QuickControls2_DIR"到包含上述之一的目录 文件。如果" Qt5QuickControls2"提供单独的开发包 或SDK,请确保它已安装。
答案 0 :(得分:0)
你的第二个答案给你最大的线索。您(至少)缺少QtQuickControls2的CMake配置文件。在Ubuntu上,如果一个软件包提供CMake配置文件(比如Qt5),它们将在软件包的-dev
版本中。确保您拥有正在使用的Qt5组件的所有-dev
个包。
如果您正在使用apt:
中的Qt5$ sudo apt-get install qtbase5-dev ## provides Core, Sql and Widgets
$ sudo apt-get install qtdeclarative5-dev ## provides Quick and Qml
$ sudo apt-get install qtmultimedia5-dev ## provides Multimedia
$ sudo apt-get install qt-quickcontrols2-5-dev ## provides QuickControls2
如果您从其来源使用Qt5,请确保您已根据其说明正确配置并安装了Qt5。
然后,使用最小CMakeLists.txt
之类的:
cmake_minimum_required(VERSION 2.8)
find_package(Qt5Core REQUIRED)
find_package(Qt5Sql REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5Multimedia REQUIRED)
find_package(Qt5Qml REQUIRED)
foreach(c Core Sql Widgets Quick Multimedia Qml)
if(${Qt5${c}_FOUND})
message(STATUS "Qt5${c} found!")
endif()
endforeach()
导致以下结果:
$ cmake .
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Qt5Core found!
-- Qt5Sql found!
-- Qt5Widgets found!
-- Qt5Quick found!
-- Qt5Multimedia found!
-- Qt5Qml found!
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nega/qt
$
如果您仍然对在Ubuntu上安装缺少的软件有疑问,可以other resources you can try。