欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CLion 创建和编译多个ROS 功能包

程序员文章站 2022-03-23 10:59:48
...
  1. cd <你要创建的工作空间存放的路径>
  2. mkdir -p <工作空间文件名>
  3. cd <工作空间文件名>
  4. mkdir -p src
  5. catkin_create_pkg <功能包名字> roscpp rospy std_msgs sensor_msgs(功能包的依赖)
  6. cd …
  7. catkin_make
    CLion 创建和编译多个ROS 功能包
  8. 在功能包文件夹的src目录下面添加功能包对应的源码文件(.cpp 笔者是用C++的)
  9. 因为CLion不会自动修改CMakeList.txt文件,添加源码文件之后,需要在CMakeList.txt里面修改内容:
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/get_laser_scan_node.cpp)
 add_executable(${PROJECT_NAME}_node src/get_laser_scan_node.cpp)

## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
 add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
 
## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
#   ${catkin_LIBRARIES}
# )
 target_link_libraries(${PROJECT_NAME}_node
   ${catkin_LIBRARIES}
 )

基本上是add_executable、add_dependencies和target_link_libraries这三句话,关于他们的作用英文解释的比较清楚了,读者自己阅读一下。
CLion 创建和编译多个ROS 功能包

  1. 然后在CLion里面编译完成就OK了。
    CLion 创建和编译多个ROS 功能包