Undefined reference to `rosidl_typesupport_c

Yeah I understand to ask questions at http://answers.ros.org but it does not appear anyone know the answer to the questions I bring up. And I simply can’t spend more time waiting around, trying to get this working. 3 weeks have passed and I’m on the brink of falling back into depression, as the only thing I found joy in lately seems out of reach.

I get an “undefined reference to” error when attempting to compile the source code below.

undefined reference to rosidl_typesupport_c__get_service_type_support_handle__example_interfaces__srv__AddTwoInts’`

Ubuntu 22.04.1 with ROS2 Humble install (desktop)
Visual Studio Code Version: 1.71.2
PlatformIO Core 6.1.4·Home 3.4.3
Platform Teensy 4.1 and micro_ROS

To the source code. This is my attempt of porting the micro-ros_addtwoints_service example from micro_ros_arduino repo.
As far as I can tell, I have all libraries properly installed and my include paths defined.

The problem seems to come from the library difference. In the example #include <micro_ros_arduino.h> was used and due to porting it to the teensy and platformio it has been changed to #include <micro_ros_platformio.h>.
However, digging deeper into the library I can’t see where the problem is.

Source code:

//#include <micro_ros_arduino.h>
#include <Arduino.h>
#include <micro_ros_platformio.h>
#include <example_interfaces/srv/add_two_ints.h>
#include <stdio.h>
#include <rcl/error_handling.h>
#include <rclc/rclc.h>
#include <rclc/executor.h>
#include <std_msgs/msg/int64.h>

rcl_node_t node;
rclc_support_t support;
rcl_allocator_t allocator;
rclc_executor_t executor;

rcl_service_t service;
rcl_wait_set_t wait_set;

example_interfaces__srv__AddTwoInts_Response res;
example_interfaces__srv__AddTwoInts_Request req;

#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){while(1){};}}
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}

void service_callback(const void * req, void * res){
  example_interfaces__srv__AddTwoInts_Request * req_in = (example_interfaces__srv__AddTwoInts_Request *) req;
  example_interfaces__srv__AddTwoInts_Response * res_in = (example_interfaces__srv__AddTwoInts_Response *) res;

  //printf("Service request value: %d + %d.\n", (int) req_in->a, (int) req_in->b);

  res_in->sum = req_in->a + req_in->b;

void setup() {

  allocator = rcl_get_default_allocator();

  // create init_options
  RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));

  // create node
  RCCHECK(rclc_node_init_default(&node, "add_twoints_client_rclc", "", &support));

  // create service
  RCCHECK(rclc_service_init_default(&service, &node, ROSIDL_GET_SRV_TYPE_SUPPORT(example_interfaces, srv, AddTwoInts), "/addtwoints"));

  // create executor
  RCCHECK(rclc_executor_init(&executor, &support.context, 1, &allocator));
  RCCHECK(rclc_executor_add_service(&executor, &service, &req, &res, service_callback));

void loop() {
  RCSOFTCHECK(rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100)));

Below is the entire compiler output I’m getting. The transports is properly selected to be Serial and configuration is matching the intended platformio.ini, which can also be found further below.

~/Documents/gitclones/AutoBot_uros$ pio run
Processing teensy41 (platform: teensy; board: teensy41; framework: arduino)
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy41.html
PLATFORM: Teensy (4.17.0) > Teensy 4.1
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 7.75MB Flash
DEBUG: Current (jlink) External (jlink)
 - framework-arduinoteensy @ 1.157.220801 (1.57) 
 - tool-teensy @ 1.157.0 (1.57) 
 - toolchain-gccarmnoneeabi @ 1.50401.190816 (5.4.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Installing pyyaml with pip at PlatformIO environment
/usr/bin/python3 -m pip install pyyaml
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (5.4.1)
Installing markupsafe==2.0.1 with pip at PlatformIO environment
/usr/bin/python3 -m pip install markupsafe==2.0.1
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: markupsafe==2.0.1 in /usr/lib/python3/dist-packages (2.0.1)
Configuring teensy41 with transport serial
micro-ROS already built
Found 93 compatible libraries
Scanning dependencies...
Dependency Graph
|-- micro_ros_platformio @ 0.0.1+sha.22cf9b6
Building in release mode
Linking .pio/build/teensy41/firmware.elf
.pio/build/teensy41/src/main.cpp.o: In function `setup':
main.cpp:(.text.setup+0x9a): undefined reference to `rosidl_typesupport_c__get_service_type_support_handle__example_interfaces__srv__AddTwoInts'
collect2: error: ld returned 1 exit status
*** [.pio/build/teensy41/firmware.elf] Error 1
========================================================== [FAILED] Took 3.82 seconds ==========================================================

And here now the platformio.ini

platform = teensy
board = teensy41
framework = arduino
board_microros_transport = serial

lib_deps =

Hello @ROS_Aotearoa, I guess that the correct place for this is the issues page of the Github repo you are using. So please open a new one so we can track this issue.

In any case, if I have understood well you are using micro_ros_platformio, and this package does not have example_interfaces package built by default, check here. You can add extra packages to the default build using this instruction

Edit: Answered here and here

1 Like