micro_ros_setup: Using generate_lib problems

Hi

I’m trying to use the generate_lib configuration to later use it to link to my project. I’m using FreeRTOS on an STM32 F7 chip, so I have my custom pipe based on a CubeMx generated code. I’ll be also using FreeRTOS+TCP and FreeRTOS+POSIX (Which I added to use micro-ros).

My intention is to build micro-ros for my target, and then have it as an artifact to link to my project during the build process. Thus, only needing to build micro-ros when adding new messages. We’ll be using Docker to have a stable image to build micro-ros.

However, I haven’t found much documentation on how to use the generate_lib configuration. So, I based myself on how the setup works. *While doing this I also noticed that micro-ros examples use CMakeForceCompiler, which is deprecated. I have my CMakeLists.txt that has all the flags and definitions needed and sets the compiler to my arm gcc/g++. It also adds the include directories for the FreeRTOS POSIX libraries, as it’s needed for all the time functions.

I also set #define configUSE_POSIX_ERRNO 1 on freertos.h

However, when I’m trying to generate the static library I run into

firmware/mcu_ws/uros/rcutils/src/filesystem.c:248:20: error: 'errno' undeclared (first use in this function)

If I’m not wrong, that means libc is not linking correctly.

Please notice that I don’t want to be forced to build my own app at this stage, I’d like to be able to have a static lib to later use. Most of the setups sort of force the user to build their app at the same time. Maybe more documentation on how it’s actually trying to link would be nice, as I’m guessing I’m forgetting something.

This is my toolchain. I’ve tried with and without the lines that have a comment that I don’t normally use

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# I normally don't use this. Added to test with micro-ros examples
set(CMAKE_CROSSCOMPILING 1)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_AR arm-none-eabi-ar)
message("-- TOOLCHAIN AR ${CMAKE_AR}")
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
message("-- TOOLCHAIN C COMPILER ${CMAKE_C_COMPILER}")
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
message("-- TOOLCHAIN CXX COMPILER ${CMAKE_CXX_COMPILER}")
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
message("-- TOOLCHAIN ASM COMPILER ${CMAKE_ASM_COMPILER}")
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
message("-- TOOLCHAIN OBJCOPY ${CMAKE_OBJCOPY}")
set(CMAKE_OBJDUMP arm-none-eabi-objdump)
message("-- TOOLCHAIN OBJDUMP ${CMAKE_OBJDUMP}")
set(CMAKE_SIZE arm-none-eabi-size)
message("-- TOOLCHAIN SIZE ${CMAKE_SIZE}")

# I normally don't use this. Added to test with micro-ros examples
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

# Flags
set(C_COMMON_FLAGS "${C_COMMON_FLAGS} -mcpu=cortex-m7 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb")

# generates a separate ELF section for each function in the source file
set(C_COMMON_FLAGS "${C_COMMON_FLAGS} -ffunction-sections")

# Enables or disables the generation of one ELF section for each variable in the source file
set(C_COMMON_FLAGS "${C_COMMON_FLAGS} -fdata-sections")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_COMMON_FLAGS}")

# Enables or disables the generation of code needed to support C++ exceptions.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")

# Disable generation of information about every class with virtual functions for use by the C++ runtime
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")

# Do not emit the extra code to use the routines specified in the C++ ABI for thread-safe initialization of local statics.
# Reduce bin size
# TODO Do we have code that could have thread safety problem?
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")

# Register destructors for objects with static storage duration with the __cxa_ atexit function rather than the atexit function
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-use-cxa-atexit")

# Add common C language flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_COMMON_FLAGS}")

add_definitions("-DUSE_HAL_DRIVER -DSTM32F746xx")

include_directories(SYSTEM
${CMAKE_CURRENT_LIST_DIR}/freertos-plus-posix/FreeRTOS-Plus-POSIX/include
${CMAKE_CURRENT_LIST_DIR}/freertos-plus-posix/FreeRTOS-Plus-POSIX/include/portable/st
${CMAKE_CURRENT_LIST_DIR}/freertos-plus-posix/include
${CMAKE_CURRENT_LIST_DIR}/freertos-plus-posix/include/private
${CMAKE_CURRENT_LIST_DIR}/freertos-plus-posix/include/FreeRTOS_POSIX
${CMAKE_CURRENT_LIST_DIR}/freertos-plus-posix/include/FreeRTOS_POSIX/sys
${CMAKE_CURRENT_LIST_DIR}/f7-drivers/STM32F7xx_HAL_Driver/Inc
${CMAKE_CURRENT_LIST_DIR}/f7-drivers/CMSIS/Device/ST/STM32F7xx/Include
${CMAKE_CURRENT_LIST_DIR}/f7-drivers/CMSIS/Include
${CMAKE_CURRENT_LIST_DIR}/f7-middlewares/Third_Party/FreeRTOS/Source/include
${CMAKE_CURRENT_LIST_DIR}/f7-middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2
${CMAKE_CURRENT_LIST_DIR}/f7-middlewares/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1
)
# I normally don't use this. Added to test with micro-ros examples
set(__BIG_ENDIAN__ 0)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Hi @mrbhjv! Thanks for sharing info about your current projects. Here at micro-ROS, we’d like to know more about your use-case. If interested to have a chat with us someday soon, don’t hesitate to contact me at francescafinocchiaro@eprosima.com!

Thanks, that makes sense. We’re currently working with no dynamic allocations purely static allocations. I’ll have to take a look at how it’s being done, as we wouldn’t want any dynamic memory if possible.

I was asking specifically about the heap as it’s something that’s usually preconfigured with freertos.h and in our case, don’t build the typical heap_4.c but the other mentioned one instead.

Regarding our use case, We’re updating our site, https://capra.ooo/ but you can look for Capra Robotics on LinkedIn to see what we’re currently working on 😃

We have been working on all embedded systems until now and we are now moving upwards on the stack. And we want to use micro-ROS to link our embedded system with the high-level computer where the agent will be.

AFAIK, FreeRTOS+TCP has UDP support. As I’m creating UDP sockets with it.

I’ll give it another spin and comment back.