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

标签 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_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上抄错了。

关于c++ - 使用资源和 ROS (catkin_make) 使用 CMake 编译 Qt 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33870652/

相关文章:

ros - 拯救新世界时凉亭卡住

c++ - C++ 17的新功能是什么?

当涉及 std::function 或 lambda 函数时,C++11 不推断类型

c++ - 如何将引用作为信号而不是对象传递

package - 如何在不共享源代码的情况下分发 ROS 包

ros - 如何从 ROS 中的 catkin 工作区生成 .deb

c++ - 使用指向数组的指针进行合并排序

c++ - 将 WCHAR 用作 CHAR?

QT和自定义菜单项(QLineEdit)

c++ - QT/C++ 通过从变量中获取其名称来将属性设置为 QObject