Creating ROS2 components with external library
Hi, I am trying to create ros2_control hardware_interface using serial communication. I am using this library for serial communication. While building the package I get the following error
/usr/bin/ld: /home/cryos/workspaces/grab_ws/install/serial/lib/libserial.a(unix.cc.o): warning: relocation against `_ZTVN6serial15SerialExceptionE' in read-only section `.text._ZN6serial15SerialExceptionD2Ev[_ZN6serial15SerialExceptionD5Ev]'
/usr/bin/ld: /home/cryos/workspaces/grab_ws/install/serial/lib/libserial.a(serial.cc.o): relocation R_X86_64_PC32 against symbol `_ZTVN6serial6SerialE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
Here is my CMakeList.txt
cmake_minimum_required(VERSION 3.8)
project(test_hardware_interface)
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(rclcpp_lifecycle REQUIRED)
find_package(lifecycle_msgs REQUIRED)
find_package(pluginlib REQUIRED)
find_package(hardware_interface)
find_package(serial REQUIRED)
add_library(
${PROJECT_NAME}
SHARED
src/test_joint_hardware_interface.cpp
)
target_include_directories(
${PROJECT_NAME}
PUBLIC
$<build_interface:${cmake_current_source_dir} include="">
$<install_interface:include>
)
ament_target_dependencies(
${PROJECT_NAME}
rclcpp
hardware_interface
lifecycle_msgs
pluginlib
rclcpp_lifecycle
serial
)
pluginlib_export_plugin_description_file(hardware_interface joint_hardware_plugin_description.xml)
install(
DIRECTORY include/
DESTINATION include
)
install(
TARGETS
${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
ament_export_include_directories(
include
)
ament_export_libraries(
${PROJECT_NAME}
)
ament_export_targets(
export_${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()
I have created a node using the library and it works well and facing this issue while building the component.
Could you please explain the error and possible solution.
Any help is appreciated!
Thank you!