How can i link the microros_static_library to a cmake project?

asked 2023-04-11 16:25:54 -0500

updated 2023-04-13 14:50:45 -0500

I followed this tutorial: https://www.youtube.com/watch?v=xbWaH... and this github link: https://github.com/micro-ROS/micro_ro... to create a custom board support for micro-ros. When i compile my project, I get the following errors:

====================[ Build | stm32f4_uros.elf | Debug ]========================
/snap/clion/234/bin/cmake/linux/x64/bin/cmake --build \/home/tzinkii/Workspace/Embedded/stm32f4_uros/cmake-build-debug --target stm32f4_uros.elf -- -j 3\
-- Minimal optimization, debug info included\
-- Configuring done\
-- Generating done\
-- Build files have been written to: /home/tzinkii/Workspace/Embedded/stm32f4_uros/cmake-build-debug\
[  2%] Linking C executable stm32f4_uros.elf

/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: error: stm32f4_uros.elf uses VFP register arguments, /home/tzinkii/Workspace/Embedded/stm32f4_uros/micro_ros_stm32cubemx_utils/microros_static_library/libmicroros/libmicroros.a(librcl-publisher.c.obj) does not\

/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: failed to merge target specific data of file /home/tzinkii/Workspace/Embedded/stm32f4_uros/micro_ros_stm32cubemx_utils/microros_static_library/libmicroros/libmicroros.a(librcl-publisher.c.obj)

...

...

...

Here is my toolchain.cmake configuration

INCLUDE(CMakeForceCompiler)

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER  arm-none-eabi-gcc)
set(CMAKE_AR arm-none-eabi-ar)
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
set(CMAKE_OBJDUMP arm-none-eabi-objdump)
set(SIZE arm-none-eabi-size)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F429ZITX_FLASH.ld)
SET(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
SET(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
SET(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
SET(LINKER_SPECS "--specs=nano.specs")
SET(LINKER_FLAGS "-Wl,--gc-sections -Wl,-T ${LINKER_SCRIPT}" CACHE STRING "" FORCE)
SET(CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS} ${LINKER_SPECS}")

Here is my CMakeLists.txt

#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
cmake_minimum_required(VERSION 3.25)

# specify cross-compilers and tools


# project settings
project(stm32f4_uros C CXX ASM)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)


# uncomment to mitigate c++17 absolute addresses warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")

# Enable assembler files preprocessing
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-x$<SEMICOLON>assembler-with-cpp>)

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
    message(STATUS "Maximum optimization for speed")
    add_compile_options(-Ofast)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
    message(STATUS "Maximum optimization for speed, debug info included")
    add_compile_options(-Ofast -g)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
    message(STATUS "Maximum optimization for size")
    add_compile_options(-Os)
else ()
    message(STATUS "Minimal optimization, debug info included")
    add_compile_options(-Og -g)
endif ()

include_directories(Core/Inc Drivers/STM32F4xx_HAL_Driver/Inc Drivers/STM32F4xx_HAL_Driver/Inc/Legacy Middlewares/Third_Party/FreeRTOS/Source/include Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F Drivers/CMSIS/Device/ST/STM32F4xx/Include Drivers/CMSIS/Include)

add_definitions(-DDEBUG -DUSE_HAL_DRIVER -DSTM32F429xx)

file(GLOB_RECURSE SOURCES "Core/*.*" "Middlewares/*.*" "Drivers/*.*")
#######################################
# micro-ROS addons
#######################################

set(SOURCES ${SOURCES}
        # Add micro-ROS utils
        "micro_ros_stm32cubemx_utils/extra_sources/custom_memory_manager.c"
        "micro_ros_stm32cubemx_utils/extra_sources/microros_allocators.c"
        "micro_ros_stm32cubemx_utils/extra_sources/microros_time.c"
        # Set here the custom transport implementation
        "micro_ros_stm32cubemx_utils/extra_sources/microros_transports/dma_transport.c"
        )

include_directories(micro_ros_stm32cubemx_utils/microros_static_library/libmicroros/microros_include)

#set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F429ZITX_FLASH.ld)

add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
add_link_options(-mcpu=cortex-m4 -mthumb -mthumb-interwork)
#add_link_options(-T ${LINKER_SCRIPT})

add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
#######################################
# micro-ROS addons end
#######################################
target_link_libraries(${PROJECT_NAME}.elf PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/micro_ros_stm32cubemx_utils/microros_static_library/libmicroros/libmicroros.a
        )

set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)

add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
        COMMAND ...
(more)
edit retag flag offensive close merge delete