0
$\begingroup$

i'm trying to transform ego-planner-swarm founded in: https://github.com/ZJU-FAST-Lab/ego-planner-swarm to ros2...

in my ros2 workspace, i have 3 packages...

bspline_opt(as library)

plan_manage

traj_utils(as library)

in plan manage i want to use other two packages as library... the problem is, i only can use whats in the header files of these two library packages in plan manage package!

for example consider this function reference:

static PolynomialTraj minSnapTraj(const Eigen::MatrixXd &Pos, const Eigen::Vector3d &start_vel,
                                    const Eigen::Vector3d &end_vel, const Eigen::Vector3d &start_acc,
                                    const Eigen::Vector3d &end_acc, const Eigen::VectorXd &Time);

in header file polynomial_traj.h.

its full definition:

PolynomialTraj PolynomialTraj::minSnapTraj(const Eigen::MatrixXd &Pos, const Eigen::Vector3d &start_vel,
                                           const Eigen::Vector3d &end_vel, const Eigen::Vector3d &start_acc,
                                           const Eigen::Vector3d &end_acc, const Eigen::VectorXd &Time)
{
  .
  .
  .
}

is in polynomial_traj.cpp. this function is in traj_utils package and its cmake is:

cmake_minimum_required(VERSION 3.8)
project(traj_utils)

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(Eigen3 3.3 REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Bspline.msg"
  "msg/DataDisp.msg"
  "msg/MultiBsplines.msg"
  "msg/PositionCommand.msg"
  DEPENDENCIES geometry_msgs std_msgs builtin_interfaces # Add packages that above messages depend on, in this case geometry_msgs for Sphere.msg
)

include_directories(include)
include_directories(SYSTEM
  ${EIGEN3_INCLUDE_DIRS})

  # Find the other package (replace 'other_package' with the actual name)
find_package(bspline_opt REQUIRED)

# Add include directories for the other package
include_directories(${bspline_opt_INCLUDE_DIRS})

# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

add_library(polynomial_traj src/polynomial_traj.cpp)
ament_target_dependencies(polynomial_traj
  rclcpp
  std_msgs
  geometry_msgs
  bspline_opt)

  ament_target_dependencies(polynomial_traj bspline_opt)
  

target_include_directories(polynomial_traj PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)
target_compile_features(polynomial_traj PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17

install(TARGETS polynomial_traj
  DESTINATION lib/${PROJECT_NAME})

# Install header files
install(DIRECTORY include/
  DESTINATION include
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_export_include_directories(include)

ament_package()

now i want to use this function in plan manage package so i include:

#include <traj_utils/polynomial_traj.h>

but when i use the function in plan_manage package, it only gets the reference which is in polynomial_traj.h and not the full definition of function and i get

"undefined reference to...(function name)"

while building with colcon... here is my plan_manage cmake:

cmake_minimum_required(VERSION 3.8)
project(plan_manage)

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(Eigen3 3.3 REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(visualization_msgs REQUIRED)

# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

include_directories(include)
include_directories(SYSTEM
  ${EIGEN3_INCLUDE_DIRS}
)

find_package(bspline_opt REQUIRED)
find_package(traj_utils REQUIRED)

# Add include directories for the other package
include_directories(${bspline_opt_INCLUDE_DIRS})
include_directories(${traj_utils_INCLUDE_DIRS})

add_executable(ego_planner_node src/ego_planner_node.cpp
                                src/ego_replan_fsm.cpp
                                src/planner_manager.cpp)

add_executable(traj_server src/traj_server.cpp)

add_executable(InTransform src/InTransform.cpp)

add_executable(TransformOut_position src/TransformOut_position.cpp)

add_executable(TransformOut_vel src/TransformOut_vel.cpp)
                                
target_include_directories(ego_planner_node PRIVATE include)  # Assuming your headers are in the include directory
target_include_directories(traj_server PRIVATE include)
target_include_directories(InTransform PRIVATE include)
target_include_directories(TransformOut_position PRIVATE include)
target_include_directories(TransformOut_vel PRIVATE include)

ament_target_dependencies(ego_planner_node
  rclcpp
  std_msgs
  nav_msgs
  sensor_msgs
  visualization_msgs
  bspline_opt
  traj_utils)

ament_target_dependencies(traj_server
  rclcpp
  std_msgs
  nav_msgs
  sensor_msgs
  visualization_msgs
  bspline_opt
  traj_utils)

ament_target_dependencies(InTransform
  rclcpp
  std_msgs
  nav_msgs
  sensor_msgs
  visualization_msgs
  bspline_opt
  traj_utils)

  ament_target_dependencies(TransformOut_position
  rclcpp
  std_msgs
  nav_msgs
  sensor_msgs
  visualization_msgs
  bspline_opt
  traj_utils)

  ament_target_dependencies(TransformOut_vel
  rclcpp
  std_msgs
  nav_msgs
  sensor_msgs
  visualization_msgs
  bspline_opt
  traj_utils)


ament_target_dependencies(ego_planner_node bspline_opt traj_utils) 

ament_target_dependencies(traj_server bspline_opt traj_utils)

target_include_directories(ego_planner_node PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)
target_compile_features(ego_planner_node PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17

install(TARGETS
  ego_planner_node
  traj_server  # Add this line to install traj_server
  InTransform
  TransformOut_position
  TransformOut_vel
  DESTINATION lib/${PROJECT_NAME})

  # Install header files
install(DIRECTORY include/
DESTINATION include
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_export_include_directories(include)

# Install launch files.
install(DIRECTORY
  launch
  DESTINATION share/${PROJECT_NAME}
)

ament_package()

should i include the cpp files also? or there is something wrong with cmake? or is it some other problem entirely?

$\endgroup$
1
  • $\begingroup$ Welcome to Robotics Stack Exchange! Please mention the error message in your question. Consider concising the code snippet by sharing a Minimal, Reproducible Example. $\endgroup$
    – ravi
    Commented Dec 16, 2023 at 10:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.