ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS2 Adding a library from another package to a library

asked 2022-07-14 11:33:57 -0500

updated 2022-07-14 11:34:14 -0500

I can add a library to executable however my main problem I could not add a library to another library.

My question is as follows: How can I add a_library in package A to b_library in package B.

https://answers.ros.org/question/3576...

edit retag flag offensive close merge delete

Comments

Could you post what you have tried so far and the error message that you are getting? It certainly will be easier to narrow it down that way.

Roberto Z. gravatar image Roberto Z.  ( 2022-07-15 02:16:31 -0500 )edit
Roberto Z. gravatar image Roberto Z.  ( 2022-07-15 03:23:40 -0500 )edit

Roberto your post is also usefull but there are many question stackoverflow and answers.ros but I did not get which is the true. However these 2 lines are keyword to also docs.ros is very usefull.

https://docs.ros.org/en/crystal/Contr...

ament_export_libraries(LibB)
ament_export_include_directories(include)
bekirbostanci gravatar image bekirbostanci  ( 2022-07-15 03:44:34 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-07-15 03:39:46 -0500

I solved the problem. I use vscode with debugging however there was a problem. I deleted install and build folders and rebuild it. It solved after rebuild.

Package A a_library

cmake_minimum_required(VERSION 3.8)
project(package_A)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(b_library REQUIRED)

set(dependencies
  rclcpp
  std_msgs
)

include_directories(include)


add_library(a_library SHARED src/a_library.cpp ) 
ament_target_dependencies(a_library ${dependencies} b_library)

add_executable(a_node src/a_node.cpp)
ament_target_dependencies(a_node  ${dependencies} b_library)
target_link_libraries(a_node a_library)



install(TARGETS a_node a_library
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)


if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()

Package B b_library

cmake_minimum_required(VERSION 3.8)
project(package_B)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

set(dependencies
  rclcpp
  std_msgs
)

include_directories(include)

add_library(b_library SHARED src/b_library.cpp) 
ament_target_dependencies(b_library ${dependencies})
ament_export_libraries(b_library)
ament_export_include_directories(include)

install(
  DIRECTORY include/
  DESTINATION include
)

install(
  TARGETS b_library
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  RUNTIME DESTINATION bin
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
edit flag offensive delete link more

Comments

I am glad to hear that you have solved the problem.

Roberto Z. gravatar image Roberto Z.  ( 2022-07-22 03:54:34 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-07-14 11:33:57 -0500

Seen: 972 times

Last updated: Jul 15 '22