C++ 使用资源和ROS(catkin_make)使用CMake编译Qt项目

C++ 使用资源和ROS(catkin_make)使用CMake编译Qt项目,c++,qt,ros,C++,Qt,Ros,我正在使用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_gu

我正在使用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>

图像/slide-groove.png
图像/slide-handle.png

我正在ubuntu 14.04机器上使用cmake 2.8.12.2。

显然这是catking的问题。我删除了由catkin创建的构建目录,再次运行catkin_make,现在它可以编译了


注意:我刚刚对cmake文件做了一个小的编辑。我复制了一个错误的,所以。

尝试
设置(CMAKE_AUTOMOC OFF)
我设置了它,但最后我只是删除了它。它什么也没做。至少在我的cmake版本中没有。因此,请关闭此问题(通知其他人,他们不应该把时间花在阅读问题上)。遗憾的是,此过程对于柳絮非常必要。如果由于不明显的原因某些东西不起作用,第一次尝试应该总是删除
build
devel
目录并再次运行,因为这通常可以解决问题:)@llya我必须再等一天才能关闭它。