Create ROS2 package from shared library (.so) and link it to node
Hello guys!
I try prepare the ROS2 package containing just a shared library in binary form (.h and .so) and than link it with my node. I think the library package works - I can see the .so files and .h file in the install directory. I am little bit lost at the node side. Linker says undefined reference error. I follow the ament_cmake documentation (https://index.ros.org/doc/ros2/Tutori...) but it is maybe little bit outdated. Documentation recommend use ament_export_interfaces, but I received warning it is deprecated way.
I am also a little bit confused with the linking debugging. There is no verbose output at top the top level (colcon). There is a colcon log in /log directory, but it is not what i want. I will try give the verbose parameter to ld using target_compile_options.
Here is my library stuff.
Package
<?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>epos_library</name>
<version>0.0.1</version>
<description>Support package for interfacing EPOS motor control unit</description>
<maintainer email="matous.pokorny@datavision.software">Matous Pokorny</maintainer>
<license>none</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
CMakeLists
cmake_minimum_required(VERSION 3.5)
project(epos_library)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
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)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
# find the 32 or 64 bit libraries
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH "x86_64")
else()
set(ARCH "x86")
endif()
message(STATUS "Detected architecture: ${ARCH}")
include_directories(include)
set(ftd2xx_LIBRARY ${PROJECT_SOURCE_DIR}/lib/${ARCH}/libftd2xx.so.1.4.6)
set(EposCmd_LIBRARY ${PROJECT_SOURCE_DIR}/lib/${ARCH}/libEposCmd.so.6.4.1.0)
add_library(ftd2xx SHARED ${ftd2xx_LIBRARY})
set_target_properties(ftd2xx PROPERTIES LINKER_LANGUAGE CXX)
add_library(EposCmd SHARED ${EposCmd_LIBRARY})
set_target_properties(EposCmd PROPERTIES LINKER_LANGUAGE CXX)
ament_export_targets(ftd2xx HAS_LIBRARY_TARGET)
ament_export_targets(EposCmd HAS_LIBRARY_TARGET)
install(
DIRECTORY include/
DESTINATION include
)
install(
TARGETS ftd2xx
EXPORT ftd2xx
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(
TARGETS EposCmd
EXPORT EposCmd
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
ament_export_include_directories(include)
ament_export_libraries(ftd2xx EposCmd)
ament_package()
Here is my node stuff.
Package
<?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>cart2</name>
<version>0.0.1</version>
<description>package for a moving program for a robot</description>
<maintainer email="matous.pokorny@datavision.cz">Matous Pokorny</maintainer>
<license>none</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>epos_package</build_depend>
<exec_depend>rclcpp</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>epos_package</exec_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
CMakeLists
cmake_minimum_required(VERSION 3.5)
project(cart2)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra ...
Hi!
Have you found a way to properly handle external non-ROS libraries in a ROS2 repository at the end?
Thanks, Cheers, GC