我正在使用ROS ament工具构建软件包。结构如下
LibA (build as shared library)
LibB (depends on LibA & build as shared library)
AppB (depends on LinB)
在LibB的package.xml中。我指定依赖为...
package.xml (under dir LibB)
<build_depend>libA</build_depend>
在AppB的package.xml中。我指定依赖为...
package.xml (under dir AppB)
<build_depend>libA</build_depend>
<build_depend>libB</build_depend>
现在构建顺序正确为..
# Topological order
- libA
- libB
- AppB
现在,当构建AppB时问题开始了,并且找不到LibA和LibB的链接。
问题
如何将LibA链接到LibB? (我应该使用什么语法)
如何将LibA,LibB链接到AppB?
最佳答案
也许您应该在LibA中使用ament_export
,在ROS2中使用this page应该会有所帮助
# CMakeLists.txt for LibA
add_library(LibA SHARED src/LibA.cpp)
ament_target_dependencies(LibA rclcpp)
ament_export_interfaces(export_LibA HAS_LIBRARY_TARGET)
ament_export_libraries(LibA)
ament_export_include_directories(include)
ament_export_dependencies(
ament_cmake
rclcpp
)
install(
TARGETS LibA
EXPORT export_LibA
LIBRARY DESTINATION lib/${PROJECT_NAME}
ARCHIVE DESTINATION lib/${PROJECT_NAME}
RUNTIME DESTINATION lib/${PROJECT_NAME}
)
install(
DIRECTORY include/
DESTINATION include
)
然后在LibB中的CMakeLists.txt
中,您应该# CMakeLists.txt for LibB
find_package(LibA REQUIRED)
add_library(LibB SHARED src/LibB.cpp)
target_include_directories(LibB PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
ament_target_dependencies(LibB
rclcpp
LibA
)
ament_export_libraries(LibB)
ament_export_include_directories(include)
ament_export_dependencies(
rclcpp
LibA
)
install(
TARGETS LibB
EXPORT export_LibB
LIBRARY DESTINATION lib/${PROJECT_NAME}
ARCHIVE DESTINATION lib/${PROJECT_NAME}
RUNTIME DESTINATION lib/${PROJECT_NAME}
)
install(
DIRECTORY include/
DESTINATION include
)
要将CMakeLists.txt
和LibA
与LibB
一起使用,我认为您需要将AppB
和ament_target_dependencies
用作参数,然后使用LibB
函数我认为您可以更改
add_executable()
的<build_depend>
标签关于c++ - 如何在Ament Tool ROS中链接共享库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56560309/