按照教程在自己创建的功能包chloe的src中编写talker和listener程序,然后配置CMakeLists.txt文件,主要在以下几个方面:
其中chloe是本人自己创建的package。
###########
## Build ##
###########
## Specify additional locations of header files
include_directories(include
${catkin_INCLUDE_DIRS}
)
## Declare a cpp library
# add_library(chloe
# src/${PROJECT_NAME}/chloe.cpp
# )
## Declare a cpp executable
# add_executable(chloe_node src/chloe_node.cpp)
## Add dependencies to the executable
# add_dependencies(chloe_node ${PROJECT_NAME})
## Specify libraries to link a library or executable target against
# target_link_libraries(chloe_node
# ${catkin_LIBRARIES}
# )
1、要保证include_directories(...)去掉注释。
2、
# add_executable(chloe_node src/chloe_node.cpp)
按照上述的形式和提示添加:
add_executable(talker src/talker.cpp)
add_executable(listener src/listener.cpp)
3、
# add_dependencies(chloe_node ${PROJECT_NAME})
按照上述的形式和提示添加:
add_dependencies(talker chloe_generate_messages_cpp)
add_dependencies(listener chloe_generate_messages_cpp)
4、
#target_link_libraries(chloe_node ${catkin_LIBRARIES})
按照上述的形式和提示添加:
target_link_libraries(talker ${catkin_LIBRARIES})
target_link_libraries(listener ${catkin_LIBRARIES})
修改完成后进行编译,在terminal中可以看到:
Built target talker
Built target listener
$roscore
$rosrun chloe talker
$rosrun chloe listener
其中chloe是本人自己创建的package。