I am building a ROS2 package to extract data from maps generated by the ROS2 package slam_toolbox . This package has a lib folder with a small implementation of karto datasets and mappers that I need to use in order to deserialize the data and generate it in a suitable format.
The package builds a shared library libkartoSlamToolbox.so, and the CMakeLists.txt exports it through ament:
ament_export_libraries(${libraries} kartoSlamToolbox)
The problem is that I have the package from apt, so my library is located at /opt/ros/humble/lib/libkartoSlamToolbox.so
My package.xml and CmakeLists.txt look like this:
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>my_slam_toolbox</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email=""></maintainer>
<license>MIT</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>slam_toolbox</depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
cmake_minimum_required(VERSION 3.8)
project(my_slam_toolbox)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/CMake/")
# list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/lib/karto_sdk/cmake)
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(slam_toolbox REQUIRED)
find_package(PCL 1.12 REQUIRED)
find_package(Boost COMPONENTS program_options serialization thread REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
include_directories(
SYSTEM
${PCL_INCLUDE_DIRS}
${slam_toolbox_INCLUDE_DIRS}
)
# Create Cpp executable
add_executable(trajectory_extractor
src/trajectory_extractor.cpp
)
target_link_libraries(trajectory_extractor
slam_toolbox::kartoSlamToolbox
${Boost_LIBRARIES}
${catkin_LIBRARIES}
)
install(DIRECTORY launch
DESTINATION share/${PROJECT_NAME})
install(DIRECTORY config
DESTINATION share/${PROJECT_NAME})
install(DIRECTORY rviz
DESTINATION share/${PROJECT_NAME})
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_package()
Edit:
I have edited the CMakeLists.txt as suggested by @ejalaa12 and I am getting the following error now:
Starting >>> my_slam_toolbox
--- stderr: my_slam_toolbox
** WARNING ** io features related to pcap will be disabled
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `main':
trajectory_extractor.cpp:(.text+0x501): undefined reference to `typeinfo for karto::Object'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `karto::ParameterManager::~ParameterManager()':
trajectory_extractor.cpp:(.text._ZN5karto16ParameterManagerD2Ev[_ZN5karto16ParameterManagerD5Ev]+0x2a): undefined reference to `karto::ParameterManager::Clear()'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `karto::AbstractParameter::AbstractParameter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, karto::ParameterManager*)':
trajectory_extractor.cpp:(.text._ZN5karto17AbstractParameterC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_16ParameterManagerE[_ZN5karto17AbstractParameterC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_16ParameterManagerE]+0x68): undefined reference to `karto::ParameterManager::Add(karto::AbstractParameter*)'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `karto::AbstractParameter::AbstractParameter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, karto::ParameterManager*)':
trajectory_extractor.cpp:(.text._ZN5karto17AbstractParameterC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_PNS_16ParameterManagerE[_ZN5karto17AbstractParameterC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_PNS_16ParameterManagerE]+0x73): undefined reference to `karto::ParameterManager::Add(karto::AbstractParameter*)'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `karto::DatasetInfo::DatasetInfo()':
trajectory_extractor.cpp:(.text._ZN5karto11DatasetInfoC2Ev[_ZN5karto11DatasetInfoC5Ev]+0x34): undefined reference to `karto::Object::Object()'
/usr/bin/ld: trajectory_extractor.cpp:(.text._ZN5karto11DatasetInfoC2Ev[_ZN5karto11DatasetInfoC5Ev]+0x501): undefined reference to `karto::Object::~Object()'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `karto::DatasetInfo::~DatasetInfo()':
trajectory_extractor.cpp:(.text._ZN5karto11DatasetInfoD2Ev[_ZN5karto11DatasetInfoD5Ev]+0x2a): undefined reference to `karto::Object::~Object()'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `karto::Dataset::Clear()':
trajectory_extractor.cpp:(.text._ZN5karto7Dataset5ClearEv[_ZN5karto7Dataset5ClearEv]+0x37): undefined reference to `karto::SensorManager::GetInstance()'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `boost::serialization::extended_type_info_typeid<karto::Object>::extended_type_info_typeid()':
trajectory_extractor.cpp:(.text._ZN5boost13serialization25extended_type_info_typeidIN5karto6ObjectEEC2Ev[_ZN5boost13serialization25extended_type_info_typeidIN5karto6ObjectEEC5Ev]+0x4a): undefined reference to `typeinfo for karto::Object'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `boost::serialization::extended_type_info_typeid<karto::Sensor>::extended_type_info_typeid()':
trajectory_extractor.cpp:(.text._ZN5boost13serialization25extended_type_info_typeidIN5karto6SensorEEC2Ev[_ZN5boost13serialization25extended_type_info_typeidIN5karto6SensorEEC5Ev]+0x4a): undefined reference to `typeinfo for karto::Sensor'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o:(.data.rel.ro._ZTIN5karto11DatasetInfoE[_ZTIN5karto11DatasetInfoE]+0x10): undefined reference to `typeinfo for karto::Object'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o:(.data.rel.ro._ZTIN5karto14LaserRangeScanE[_ZTIN5karto14LaserRangeScanE]+0x10): undefined reference to `typeinfo for karto::SensorData'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `karto::Object const* boost::serialization::smart_cast_impl::pointer<karto::Object const*>::polymorphic::cast<karto::NonCopyable const>(karto::NonCopyable const*)':
trajectory_extractor.cpp:(.text._ZN5boost13serialization15smart_cast_impl7pointerIPKN5karto6ObjectEE11polymorphic4castIKNS3_11NonCopyableEEES6_PT_[_ZN5boost13serialization15smart_cast_impl7pointerIPKN5karto6ObjectEE11polymorphic4castIKNS3_11NonCopyableEEES6_PT_]+0x31): undefined reference to `typeinfo for karto::Object'
/usr/bin/ld: CMakeFiles/trajectory_extractor.dir/src/trajectory_extractor.cpp.o: in function `karto::DatasetInfo const* boost::serialization::smart_cast_impl::pointer<karto::DatasetInfo const*>::polymorphic::cast<karto::Object const>(karto::Object const*)':
trajectory_extractor.cpp:(.text._ZN5boost13serialization15smart_cast_impl7pointerIPKN5karto11DatasetInfoEE11polymorphic4castIKNS3_6ObjectEEES6_PT_[_ZN5boost13serialization15smart_cast_impl7pointerIPKN5karto11DatasetInfoEE11polymorphic4castIKNS3_6ObjectEEES6_PT_]+0x38): undefined reference to `typeinfo for karto::Object'
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/trajectory_extractor.dir/build.make:309: trajectory_extractor] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:137: CMakeFiles/trajectory_extractor.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
---
Failed <<< my_slam_toolbox [6.67s, exited with code 2]
Summary: 0 packages finished [7.22s]
1 package failed: my_slam_toolbox
1 package had stderr output: my_slam_toolbox
```