Linking problem with serialization

Hello,
I was working in migrating a program from ros1 to ros2, all seems to be alright but at the end of the compilation an error appears. It seems that the code is alright and its a problem with the linking. I am working in a docker of ros2 humble. Also this error only show when serialization is used.
This is the error i keep getting

/usr/bin/ld: CMakeFiles/test_rec_msgs_node.dir/src/data_handler.cpp.o: in function `rclcpp::Serialization<std::shared_ptr<std_msgs::msg::UInt8_<std::allocator<void> > > >::Serialization()':
ros2_humble  | data_handler.cpp:(.text._ZN6rclcpp13SerializationISt10shared_ptrIN8std_msgs3msg6UInt8_ISaIvEEEEEC2Ev[_ZN6rclcpp13SerializationISt10shared_ptrIN8std_msgs3msg6UInt8_ISaIvEEEEEC5Ev]+0x16): undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<std::shared_ptr<std_msgs::msg::UInt8_<std::allocator<void> > > >()'

This is an example of one of where the errors is ()

    std::shared_ptr<rclcpp::SerializedMessage> serialized_msg;
    using MessageT = std_msgs::msg::UInt8;
    MessageT msg; 
    auto serializer = rclcpp::Serialization<MessageT>();
    serializer.deserialize_message(serialized_msg.get(), &msg);

    pub_timer_about_to_finish_->publish(msg);

It could be a problem of the cmake ? It seems to be alright I checked all the packages and they are included, i can attach the cmake if necessary.
Thank you for your time and reading this post :slight_smile:

Hi @fernando.cuadrado.cas, the error is because the linker is unable to find the symbol for the type support handle needed for serialization and deserialization of messages. In ROS 2, the rclcpp::Serialization template requires the availability of type support for the message type. The error occurs because the linker cannot find the necessary type support symbol for std_msgs::msg::UInt8.

To fix this, you need to make sure that the type support for the message type you’re using is correctly linked and available.
First make sure that you included the header in your code:

#include "std_msgs/msg/u_int8.hpp"

Then you may need to explicitly instantiate the template for rclcpp::Serialization with std_msgs::msg::UInt8. You can do this by adding the following at the end of your .cpp file:

template class rclcpp::Serialization<std_msgs::msg::UInt8>;

It also could be that there is a problem with you CMakeLists file so make sure that your CMakeLists.txt file is correctly linking against the necessary libraries. Specifically, that you are linking against the std_msgs package.

Finally it was an error in another place in a function that uses serialization, and we we where trying to use pointers in a function that didn’t allowed that . Thanks for your reply :slight_smile:

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.