情景:
- ros_package
- include/ros_package
- aaa.h
- bbb.h
- src
- aaa.cpp
- bbb.cpp
- include/ros_package
此时如果想在b.cpp中引用a.h定义的库,则需要在CMakeList.txt的文档最后,在bbb的target_link_libraries中,添加aaa:
target_link_libraries(bbb
aaa
${catkin_LIBRARIES}
)
可以理解为在bbb中建立指向aaa的链接,从而调用aaa中定义的各种库文件
补注:
在xxx.cpp向xxx.h的链接:
add_dependencies(xxx ${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS})
target_link_libraries(xxx ${catkin_LIBRARIES})