Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to link when targeting Arduino H7 on PlatformIO #774

Closed
tnagyzambo opened this issue Feb 18, 2022 · 4 comments
Closed

Failure to link when targeting Arduino H7 on PlatformIO #774

tnagyzambo opened this issue Feb 18, 2022 · 4 comments
Assignees

Comments

@tnagyzambo
Copy link

I am trying to replicate the PlatformIO STM32 template for the Arduino H7.

The platformio.ini file:

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino

build_flags =
    -L ./.pio/libdeps/portenta_h7_m7/micro_ros_arduino/src/cortex_m7/
    -l microros
    -D TARGET_PORTENTA_H7_M7

lib_deps =
    https://github.com/micro-ROS/micro_ros_arduino

Results in the error:

Processing portenta_h7_m7 (platform: ststm32; board: portenta_h7_m7; framework: arduino)
--------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/portenta_h7_m7.html
PLATFORM: ST STM32 (15.2.0) > Arduino Portenta H7 (M7 core)
HARDWARE: STM32H747XIH6 480MHz, 511.35KB RAM, 768KB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-arduino-mbed 2.6.1 
 - tool-dfuutil 1.9.200310 
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 32 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <micro_ros_arduino> 0.0.4+sha.58d23b4
|   |-- <Ethernet> 1.0.0
|   |   |-- <SocketWrapper> 1.0
|   |-- <SPI>
|   |-- <WiFi> 1.0
|   |   |-- <SocketWrapper> 1.0
Building in release mode
Linking .pio/build/portenta_h7_m7/firmware.elf
/Users/tnagyzambo/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: cannot find -lmicroros
collect2: error: ld returned 1 exit status
*** [.pio/build/portenta_h7_m7/firmware.elf] Error 1
@tnagyzambo
Copy link
Author

So the error turned out to be a rather embarrassing typo, the .ini file should be as follow:

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino

build_flags =
    -L ./.pio/libdeps/portenta_h7_m7/micro_ros_arduino/src/cortex-m7/fpv5-d16-softfp/
    -l libmicroros
    -D TARGET_PORTENTA_H7_M7

lib_deps =
    https://github.com/micro-ROS/micro_ros_arduino

However now a new linking error appears seemingly related to the test cases?

Processing portenta_h7_m7 (platform: ststm32; board: portenta_h7_m7; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/portenta_h7_m7.html
PLATFORM: ST STM32 (15.2.0) > Arduino Portenta H7 (M7 core)
HARDWARE: STM32H747XIH6 480MHz, 511.35KB RAM, 768KB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-arduino-mbed 2.6.1 
 - tool-dfuutil 1.9.200310 
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 32 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <micro_ros_arduino> 0.0.4+sha.58d23b4
|   |-- <Ethernet> 1.0.0
|   |   |-- <SocketWrapper> 1.0
|   |-- <SPI>
|   |-- <WiFi> 1.0
|   |   |-- <SocketWrapper> 1.0
Building in release mode
Linking .pio/build/portenta_h7_m7/firmware.elf
.pio/libdeps/portenta_h7_m7/micro_ros_arduino/src/cortex-m7/fpv5-d16-softfp/libmicroros.a(libactionlib_msgs__rosidl_typesupport_introspection_c-goal_status__type_support.c.obj): In function `GoalStatus__rosidl_typesupport_introspection_c__GoalStatus_init_function':
goal_status__type_support.c:(.text.GoalStatus__rosidl_typesupport_introspection_c__GoalStatus_init_function+0x0): multiple definition of `GoalStatus__rosidl_typesupport_introspection_c__GoalStatus_init_function'
.pio/libdeps/portenta_h7_m7/micro_ros_arduino/src/cortex-m7/fpv5-d16-softfp/libmicroros.a(libaction_msgs__rosidl_typesupport_introspection_c-goal_status__type_support.c.obj):goal_status__type_support.c:(.text.GoalStatus__rosidl_typesupport_introspection_c__GoalStatus_init_function+0x0): first defined here
.pio/libdeps/portenta_h7_m7/micro_ros_arduino/src/cortex-m7/fpv5-d16-softfp/libmicroros.a(libactionlib_msgs__rosidl_typesupport_introspection_c-goal_status__type_support.c.obj): In function `GoalStatus__rosidl_typesupport_introspection_c__GoalStatus_fini_function':
goal_status__type_support.c:(.text.GoalStatus__rosidl_typesupport_introspection_c__GoalStatus_fini_function+0x0): multiple definition of `GoalStatus__rosidl_typesupport_introspection_c__GoalStatus_fini_function'
.pio/libdeps/portenta_h7_m7/micro_ros_arduino/src/cortex-m7/fpv5-d16-softfp/libmicroros.a(libaction_msgs__rosidl_typesupport_introspection_c-goal_status__type_support.c.obj):goal_status__type_support.c:(.text.GoalStatus__rosidl_typesupport_introspection_c__GoalStatus_fini_function+0x0): first defined here
.pio/libdeps/portenta_h7_m7/micro_ros_arduino/src/cortex-m7/fpv5-d16-softfp/libmicroros.a(libactionlib_msgs__rosidl_typesupport_introspection_c-goal_status_array__type_support.c.obj): In function `GoalStatusArray__rosidl_typesupport_introspection_c__size_function__GoalStatus__status_list':
goal_status_array__type_support.c:(.text.GoalStatusArray__rosidl_typesupport_introspection_c__size_function__GoalStatus__status_list+0x0): multiple definition of `GoalStatusArray__rosidl_typesupport_introspection_c__size_function__GoalStatus__status_list'
...

file.log

@Acuadros95 Acuadros95 self-assigned this Feb 21, 2022
@pablogs9
Copy link
Member

pablogs9 commented Feb 21, 2022

There are some linker flags issues that seems that are not present in the Arduino IDE. I have been able to build allowing duplicated symbols and removing not used symbols sections:

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino

build_flags =
    -L ./.pio/libdeps/portenta_h7_m7/micro_ros_arduino/src/cortex-m7/fpv5-d16-softfp/
    -l libmicroros
    -D TARGET_PORTENTA_H7_M7
    -fdata-sections
    -ffunction-sections
    -Wl,--gc-sections
    -Wl,--unresolved-symbols=ignore-in-object-files
    -Wl,--allow-multiple-definition
    -Wl,-n


lib_deps =
    https://github.com/micro-ROS/micro_ros_arduino

@Acuadros95
Copy link
Contributor

Hi, this issue is explained here: ROBOTIS-GIT/OpenCR#294, to fix this, we need to modify the linker flags.

To do this, create a python script fix_linker.py on your directory and modify the linker flags manually:

Import("env")
env["_LIBFLAGS"] =  ('-Wl,--start-group -Wl,--whole-archive '
                    '${_stripixes(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, LIBPREFIXES, '
                    'LIBSUFFIXES, __env__)} -Wl,--no-whole-archive -lstdc++ '
                    '-lsupc++ -lm -lc -lgcc -lnosys -lmicroros -Wl,--end-group')

Now add it to your platformio.ini like this: extra_scripts = fix_linker.py and delete the -l libmicroros line on build_flags.

Your final .ini file should look like this:

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino
extra_scripts = fix_linker.py

lib_deps =
    https://github.com/micro-ROS/micro_ros_arduino

build_flags =
    -L ./.pio/libdeps/portenta_h7_m7/micro_ros_arduino/src/cortex-m7/fpv5-d16-softfp/
    -D TARGET_PORTENTA_H7_M7

@tnagyzambo
Copy link
Author

Thanks, I can confirm that both solutions work.

From my (limited) understanding of what's happening here it seems that @Acuadros95's solutions is more appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants