2

I am building my packages with ROS ament tools. structure is as below

LibA (build as shared library)

LibB (depends on LibA & build as shared library)

AppB (depends on LinB)

in package.xml of LibB. I specified dependency as ...

package.xml (under dir LibB)

<build_depend>libA</build_depend>

in package.xml of AppB. I specified dependency as ...

package.xml (under dir AppB)

<build_depend>libA</build_depend>
<build_depend>libB</build_depend>

Now build order is correct as ..

# Topological order
 - libA
 - libB
 - AppB

Now issue starts when bulding AppB, and it can't find link for LibA and LibB.

Question

How can I link LibA to LibB ? (what syntax should I use)

How can I link LibA,LibB to AppB ?

Jai
  • 1,292
  • 4
  • 21
  • 41

1 Answers1

1

Perhaps you should use ament_export in LibA CMakeLists.txt, this page from ROS2 should help

# 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
)

and then in CMakeLists.txt from LibB you should have

# 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
)

To use LibA and LibB with AppB, I think you need to use ament_target_dependencies with LibB as argument and then use add_executable() function

I think you could change the <build_depend> tag for <depend>

Community
  • 1
  • 1
ignacio
  • 1,181
  • 2
  • 15
  • 28