使用资源和 ROS 使用 CMake 编译 Qt 项目 (catkin_make)
Compiling a Qt project with CMake using resources and ROS (catkin_make)
我正在使用cmake编译一个Qt项目(它也使用catkin,因为这实际上是一个ROS项目,但我认为问题与此无关)。在我开始使用图像并添加一个 qrc 文件来处理它们之前,一切都编译并运行良好。当我 运行 cmake 我得到这个错误:
make[2]: *** No rule to make target `/home/myname/development/ros/src/dls_gui/images/slide-groove.png', needed by `dls_gui/qrc_dls_gui.cpp'. Stop.
我的CMakeList文件是这样的:
cmake_minimum_required(VERSION 2.8.11)
project(dls_gui)
# Find the QtWidgets library
find_package(Qt5Widgets)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# catkin related
find_package(catkin REQUIRED COMPONENTS roscpp sensor_msgs urdf)
include_directories(${catkin_INCLUDE_DIRS} include)
# source, header and resources files list
set(CPP_SOURCES src/main.cpp src/mainwindow.cpp src/basewidget.cpp src/rosQtNode.cpp src/joints_sliders.cpp src/superslider.cpp)
set(CPP_HDRS include/mainwindow.h include/basewidget.h include/rosQtNode.hpp include/joints_sliders.hpp include/superslider.hpp)
set(QRC_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dls_gui.qrc)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
## Declare a catkin package
catkin_package()
# Add the include directories for the Qt 5 Widgets module to
# the compile lines.
include_directories(${Qt5Widgets_INCLUDE_DIRS})
# Use the compile definitions defined in the Qt 5 Widgets module
add_definitions(${Qt5Widgets_DEFINITIONS})
# Generate headers from ui files
qt5_wrap_ui(UIS_HDRS src/mainwindow.ui)
# Generate moc files from cpp
qt5_wrap_cpp(MOC_SOURCES ${CPP_SOURCES} ${CPP_HDRS})
# Generate resources
qt5_add_resources(RESOURCES_RCC ${RESOURCE})
# Add compiler flags for building executables (-fPIE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} -std=c++11")
## Ros include dirs
include_directories(include ${catkin_INCLUDE_DIRS})
# Tell CMake to create the helloworld executable
add_executable(dls_gui ${CPP_SOURCES} ${UIS_HDRS} ${MOC_SOURCES} ${QRC_RESOURCES})
add_executable(testRos src/testRos.cpp)
qt5_use_modules(dls_gui Widgets)
#Link the helloworld executable to the Qt 5 widgets library.
target_link_libraries(dls_gui Qt5::Widgets ${catkin_LIBRARIES})
target_link_libraries(testRos ${catkin_LIBRARIES})
qrc 文件是:
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/images">
<file>images/slide-groove.png</file>
<file>images/slide-handle.png</file>
</qresource>
</RCC>
我在 ubuntu 14.04 机器上使用 cmake 2.8.12.2。
很明显这是猫叫的问题。我删除了catkin创建的构建目录,运行再次catkin_make,现在可以编译了。
注意:我只是对 cmake 文件做了一个小的编辑。我在SO上抄错了
我正在使用cmake编译一个Qt项目(它也使用catkin,因为这实际上是一个ROS项目,但我认为问题与此无关)。在我开始使用图像并添加一个 qrc 文件来处理它们之前,一切都编译并运行良好。当我 运行 cmake 我得到这个错误:
make[2]: *** No rule to make target `/home/myname/development/ros/src/dls_gui/images/slide-groove.png', needed by `dls_gui/qrc_dls_gui.cpp'. Stop.
我的CMakeList文件是这样的:
cmake_minimum_required(VERSION 2.8.11)
project(dls_gui)
# Find the QtWidgets library
find_package(Qt5Widgets)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# catkin related
find_package(catkin REQUIRED COMPONENTS roscpp sensor_msgs urdf)
include_directories(${catkin_INCLUDE_DIRS} include)
# source, header and resources files list
set(CPP_SOURCES src/main.cpp src/mainwindow.cpp src/basewidget.cpp src/rosQtNode.cpp src/joints_sliders.cpp src/superslider.cpp)
set(CPP_HDRS include/mainwindow.h include/basewidget.h include/rosQtNode.hpp include/joints_sliders.hpp include/superslider.hpp)
set(QRC_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dls_gui.qrc)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
## Declare a catkin package
catkin_package()
# Add the include directories for the Qt 5 Widgets module to
# the compile lines.
include_directories(${Qt5Widgets_INCLUDE_DIRS})
# Use the compile definitions defined in the Qt 5 Widgets module
add_definitions(${Qt5Widgets_DEFINITIONS})
# Generate headers from ui files
qt5_wrap_ui(UIS_HDRS src/mainwindow.ui)
# Generate moc files from cpp
qt5_wrap_cpp(MOC_SOURCES ${CPP_SOURCES} ${CPP_HDRS})
# Generate resources
qt5_add_resources(RESOURCES_RCC ${RESOURCE})
# Add compiler flags for building executables (-fPIE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} -std=c++11")
## Ros include dirs
include_directories(include ${catkin_INCLUDE_DIRS})
# Tell CMake to create the helloworld executable
add_executable(dls_gui ${CPP_SOURCES} ${UIS_HDRS} ${MOC_SOURCES} ${QRC_RESOURCES})
add_executable(testRos src/testRos.cpp)
qt5_use_modules(dls_gui Widgets)
#Link the helloworld executable to the Qt 5 widgets library.
target_link_libraries(dls_gui Qt5::Widgets ${catkin_LIBRARIES})
target_link_libraries(testRos ${catkin_LIBRARIES})
qrc 文件是:
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/images">
<file>images/slide-groove.png</file>
<file>images/slide-handle.png</file>
</qresource>
</RCC>
我在 ubuntu 14.04 机器上使用 cmake 2.8.12.2。
很明显这是猫叫的问题。我删除了catkin创建的构建目录,运行再次catkin_make,现在可以编译了。
注意:我只是对 cmake 文件做了一个小的编辑。我在SO上抄错了