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
相关推荐
Mr.Q39 分钟前
Qt多边形填充/不填充绘制
qt
可峰科技1 小时前
斗破QT编程入门系列之二:认识Qt:编写一个HelloWorld程序(四星斗师)
开发语言·qt
7年老菜鸡3 小时前
策略模式(C++)三分钟读懂
c++·qt·策略模式
饮啦冰美式4 小时前
ROS2humble版本使用colcon构建包
ros
huanggang9827 小时前
在Ubuntu22.04上使用Qt Creator开发ROS2项目
qt·ros2
老秦包你会7 小时前
Qt第三课 ----------容器类控件
开发语言·qt
spygg8 小时前
Qt低版本多网卡组播bug
qt·组播·多网卡组播·qt5.7.0
码农客栈9 小时前
qt QWebSocketServer详解
qt
plmm烟酒僧10 小时前
Windows下QT调用MinGW编译的OpenCV
开发语言·windows·qt·opencv
Black_Friend11 小时前
关于在VS中使用Qt不同版本报错的问题
开发语言·qt