cd robot_test/src
catkin_create_pkg amin roscpp rospy std_msgs(rosmsg)创建模块命名并同时添加依赖 cd hello vim hello.cpp 写程序
catkin_create_pkg hello 创建模块并命名 添加cpp文件支持 CMakeLists.txt 文件中 find_package(catkin REQUIRED COMPONENTS roscpp) 加上COMPONENTS roscpp, 表示支持cpp组件 在包的清单文件package.xml 中列出依赖库
<build_depend>roscpp</build_depend> <run_depend>roscpp</run_depend>
声明可执行文件
add_executable(executable-name source-files)
target_link_libraries(executable-name ${catkin_LIBRARIES}) 例hello.cpp文件(每写一个文件都要添加两行): add_executable(hello hello.cpp) target_link_libraries(hello ${catkin_LIBRARIES})
编译工作区 cd ~/catkin_ws/robot_test catkin_make catkin_make_isolated --install 编译时有可能会提示找不到ros.h,解决办法: 来到CMakeLists.txt, 改成如下 原本是有注释的, 把注释去掉 include_directories( include ${catkin_INCLUDE_DIRS} )
|