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
相关推荐
c1s2d3n4cs3 小时前
Qt使用QZipWriter和QZipReader来解压、压缩文件
开发语言·qt
qq_430583976 小时前
QT笔记- QTreeView + QFileSystemModel 当前位置的保存与恢复 #选中 #保存当前索引
开发语言·笔记·qt
小王爱吃月亮糖7 小时前
QT-QVariant类应用
开发语言·c++·笔记·qt·visual studio
阿松のblog7 小时前
pyQt5实现目标检测可视化001
开发语言·qt·目标检测
沐泽Mu17 小时前
嵌入式学习-QT-Day05
开发语言·c++·qt·学习
StringerChen18 小时前
Qt ui提升窗口的头文件找不到
开发语言·qt
沐泽Mu20 小时前
嵌入式学习-QT-Day07
c++·qt·学习·命令模式
沐泽Mu20 小时前
嵌入式学习-QT-Day09
开发语言·qt·学习
林浔09061 天前
QT信号槽
开发语言·qt
kiiila1 天前
【Qt】编辑框/按钮控件---实现HelloWorld
开发语言·qt