win10 下 ros + Qt 工程CMakeLists.txt

win10 下 ros + Qt 工程CMakeLists.txt

系统:win10

ros: melodic

Qt: 5.12.12

源码目录: D:\workspace\catkin_qt

示例代码 https://github.com/ncnynl/ros-qt.git

由于示例代码是Qt4 ,目前我是用QT5,所以CMakeLists.txt 修改如下

CMakeLists.txt

bash 复制代码
##############################################################################
# CMake
##############################################################################

cmake_minimum_required(VERSION 2.8.0)
project(msg)

set (TARGET msg)

set(CMAKE_CXX_STANDARD 11)
add_compile_options(-std=c++11)

##############################################################################
# Catkin
##############################################################################

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)

include_directories(
    ${catkin_INCLUDE_DIRS}
    # include ui generate .h file
    ${CMAKE_BINARY_DIR}/code02-msg
)
# Use this to define what the package will export (e.g. libs, headers).
# Since the default here is to produce only a binary, we don't worry about
# exporting anything. 
catkin_package()

##############################################################################
# Qt Environment
##############################################################################

## This setting causes Qt's "MOC" generation to happen automatically.
# set(CMAKE_AUTOMOC ON)
# set(CMAKE_AUTOUIC ON)
# set(CMAKE_AUTORCC ON)

find_package(Qt5 COMPONENTS Gui Widgets Core REQUIRED)
set(QT_LIBRARIES Qt5::Gui Qt5::Widgets)



##############################################################################
# Sections
##############################################################################

##############################################################################
# Sources
##############################################################################

file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)
file(GLOB_RECURSE HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/msg/*.hpp)
file(GLOB_RECURSE RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS resources/*.qrc)
file(GLOB_RECURSE UI RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS ui/*.ui)


qt5_wrap_cpp(SOURCES ${HEADERS})
qt5_wrap_ui(SOURCES ${UI})
qt5_add_resources(SOURCES ${RESOURCES})

##############################################################################
# Binaries
##############################################################################

add_executable(${TARGET} ${SOURCES} )
target_link_libraries(${TARGET} ${QT_LIBRARIES} ${catkin_LIBRARIES})
install(TARGETS ${TARGET} RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

message("CATKIN_PACKAGE_BIN_DESTINATION : " ${CATKIN_PACKAGE_BIN_DESTINATION})
message("CATKIN_PACKAGE_ETC_DESTINATION : " ${CATKIN_PACKAGE_ETC_DESTINATION})
message("CATKIN_PACKAGE_INCLUDE_DESTINATION : " ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
message("CATKIN_PACKAGE_LIB_DESTINATION : " ${CATKIN_PACKAGE_LIB_DESTINATION})
message("CATKIN_PACKAGE_PYTHON_DESTINATION : " ${CATKIN_PACKAGE_PYTHON_DESTINATION})
message("CATKIN_PACKAGE_SHARE_DESTINATION : " ${CATKIN_PACKAGE_SHARE_DESTINATION})
message("CMAKE_BINARY_DIR":${CMAKE_BINARY_DIR})

编译

win10下 打开 ros-melodic 命令行快捷方式:

切换到工作目录 :

bash 复制代码
C:\Windows\System32> cd /d D:\workspace\catkin_qt

添加工作目录环境变量:

bash 复制代码
D:\workspace\catkin_qt> cmd /k D:\workspace\catkin_qt\devel\setup.bat
bash 复制代码
catkin_make 

运行

bash 复制代码
roscore
bash 复制代码
rosrun msg msg
相关推荐
_OP_CHEN4 小时前
从零开始的Qt开发指南:(七)Qt常用控件之按钮类控件深度解析:从 QPushButton 到单选 / 复选的实战指南
qt·前端开发·qradiobutton·qpushbutton·qcheckbox·qt常用控件·gui界面开发
友友马16 小时前
『QT』窗口 (一)
开发语言·数据库·qt
2739920291 天前
AES加解密(QT)
qt
颜*鸣&空2 天前
QT实现串口通信+VSPD+串口调试工具
开发语言·qt
颜*鸣&空2 天前
QT程序实现串口通信案例
开发语言·qt
Main. 242 天前
从0到1学习Qt -- 常见控件之显示类控件
qt·学习
qq_401700412 天前
Qt中事件循环与并发机制的协同工作
qt
qq_401700413 天前
Qt Positioning 模块访问设备地理位置信息
开发语言·qt
闫有尽意无琼3 天前
银河麒麟v11 arm编译Qt creator8.0.2报错
开发语言·qt
lqj_本人3 天前
鸿蒙Qt触控疑云:事件传递丢失与坐标偏移修复
qt·华为·harmonyos