Seed Studio Xiao MG24 - Linking of Edge Arduino library failing due to dual inclusion of TFLite library

Question/Issue:
Xiao MG24 - Arduino Studio sketch compilation failing because duplication of TFLite library

Project ID:
825807

Context/Use case:
Captured datasets using the the MG24 IMU (accelerometer, gyroscope) and generated a model for gesture detection.
Downloaded the model for inferencing as a Arduino library (MG24_Sense_inferencing.h)
Created a simple sketch that reads the IMU data and passes it to the library for inferencing.
But compilation is failing because both the Edge Impulse library and the Silabs SDK library for the MG24 include the TensorFlow Lite library - as .o files in the Edge Impulse library, and as a pre-compiled file from Silabs SDK (Gecko library - gsdk.a file)

Steps Taken:

Downloaded the Edge Impulse lib as a .zip file - ei-mg24-sense-arduino-1.0.3.zip
Included it in my sketch (#include <MG24_Sense_inferencing.h>)
Tried to compile but it fails at linker stage (ld) for all functions of the TFLite library with 'multiple definition of ’ the functions
Expected Outcome:
To compile and upload the sketch to the MG24 MCU

Actual Outcome:
Many linker errors due to dual definitions of TFLite functions. Two examples:

ld.exe:
C:\Users\Luis\AppData\Local\Arduino15\packages\SiliconLabs\hardware\silabs\3.0.0\variants\xiao_mg24/ble_silabs/gsdk.a(unidirectional_sequence_lstm.o):
in function tflite::Register_UNIDIRECTIONAL_SEQUENCE_LSTM()': /Users/tajozsi/Library/Arduino15/packages/SiliconLabs/hardware/silabs/3.0.0/package/gen/aiml_2.0.0/third_party/tflite-micro/tensorflow/lite/micro/kernels/cmsis_nn/unidirectional_sequence_lstm.cc:672: multiple definition of tflite::Register_UNIDIRECTIONAL_SEQUENCE_LSTM()'; C:\Users\Luis\AppData\Local\arduino\sketches\05E61CED255EDA90751A781933D93C90\libraries\MG24_Sense_inferencing\edge-impulse-sdk\tensorflow\lite\micro\kernels\objs.a(unidirectional_sequence_lstm.cpp.o):
c:\src\Arduino\libraries\MG24_Sense_inferencing\src\edge-impulse-sdk\tensorflow\lite\micro\kernels/unidirectional_sequence_lstm.cpp:585: first defined here

ld.exe:
C:\Users\Luis\AppData\Local\Arduino15\packages\SiliconLabs\hardware\silabs\3.0.0\variants\xiao_mg24/noradio/libtflm.a(kernel_util.cc.obj):
in function tflite::micro::GetMutableEvalInput(TfLiteContext const*, TfLiteNode const*, int)': C:/Users/anmahade/src/gsdk/extension/aiml-extension/third_party/tflite-micro/tensorflow/lite/micro/kernels/kernel_util.cc:63: multiple definition of tflite::micro::GetMutableEvalInput(TfLiteContext const*, TfLiteNode const*, int)'; C:\Users\Luis\AppData\Local\arduino\sketches\05E61CED255EDA90751A781933D93C90\libraries\MG24_Sense_inferencing\edge-impulse-sdk\tensorflow\lite\micro\kernels\objs.a(kernel_util_micro.cpp.o):c:\src\Arduino\libraries\MG24_Sense_inferencing\src\edge-impulse-sdk\tensorflow\lite\micro\kernels/kernel_util_micro.cpp:60: first defined here

Reproducibility:

[X] Always
[ ] Sometimes
[ ] Rarely
Environment:

Platform: Seed Studio Xiao MG24 - Silabs EFR32MG24 (Cortex-M33 78Mhz) MCU
Build Environment Details: Arduino 2.3.6 with Arduino Core for Silicon Labs devices 3.0.0
OS Version: Windows 10
Edge Impulse Version (Firmware):
EI_STUDIO_VERSION_MAJOR 1
EI_STUDIO_VERSION_MINOR 79
EI_STUDIO_VERSION_PATCH 1

Edge Impulse CLI Version:
Project Version: 1.0.3
Custom Blocks / Impulse Configuration: no custom blocks used (all defaults suggested by the site)
Logs/Attachments:

For all TFLite functions , linker multiple definiton errors as stated above:

Examples:
ld.exe:
C:\Users\Luis\AppData\Local\Arduino15\packages\SiliconLabs\hardware\silabs\3.0.0\variants\xiao_mg24/ble_silabs/gsdk.a(unidirectional_sequence_lstm.o):
in function tflite::Register_UNIDIRECTIONAL_SEQUENCE_LSTM()': /Users/tajozsi/Library/Arduino15/packages/SiliconLabs/hardware/silabs/3.0.0/package/gen/aiml_2.0.0/third_party/tflite-micro/tensorflow/lite/micro/kernels/cmsis_nn/unidirectional_sequence_lstm.cc:672: multiple definition of tflite::Register_UNIDIRECTIONAL_SEQUENCE_LSTM()'; C:\Users\Luis\AppData\Local\arduino\sketches\05E61CED255EDA90751A781933D93C90\libraries\MG24_Sense_inferencing\edge-impulse-sdk\tensorflow\lite\micro\kernels\objs.a(unidirectional_sequence_lstm.cpp.o):
c:\src\Arduino\libraries\MG24_Sense_inferencing\src\edge-impulse-sdk\tensorflow\lite\micro\kernels/unidirectional_sequence_lstm.cpp:585: first defined here

ld.exe:
C:\Users\Luis\AppData\Local\Arduino15\packages\SiliconLabs\hardware\silabs\3.0.0\variants\xiao_mg24/noradio/libtflm.a(kernel_util.cc.obj):
in function tflite::micro::GetMutableEvalInput(TfLiteContext const*, TfLiteNode const*, int)': C:/Users/anmahade/src/gsdk/extension/aiml-extension/third_party/tflite-micro/tensorflow/lite/micro/kernels/kernel_util.cc:63: multiple definition of tflite::micro::GetMutableEvalInput(TfLiteContext const*, TfLiteNode const*, int)'; C:\Users\Luis\AppData\Local\arduino\sketches\05E61CED255EDA90751A781933D93C90\libraries\MG24_Sense_inferencing\edge-impulse-sdk\tensorflow\lite\micro\kernels\objs.a(kernel_util_micro.cpp.o):c:\src\Arduino\libraries\MG24_Sense_inferencing\src\edge-impulse-sdk\tensorflow\lite\micro\kernels/kernel_util_micro.cpp:60: first defined here

Additional Information:

I asked at the Silabs forums if there’s a way to avoid inclusion of TFlite lib in their Arduino core but I think it’s difficult it being a pre-compiled binary blob (gsdk.a). Is there any way (flag, option) when generating the Edge Impulse Arduino lib to tell it to exclude the TFLite library, since it alread exists at other parts of the project for a targeted MCU (in this case the MG24)? Or else there will be no way to use Edge Impulse for many Silabs MCUs that use the same core lib (Gecko).
Thanks!

1 Like

Welcome to the forum @lderani

Thanks for sharing this, I haven’t tried Arduino Lib on the G24, it looks like a clash from this betweeen two instances of TFlite, :

``multiple definition of tflite::micro::GetMutableEvalInput(TfLiteContext const*, TfLiteNode const*, int)';

You can set flags for sure to exclude portions if you want to export as a C++ library and try compiling for yourself:

C and C++ Compiler flags

CFLAGS += -Wall # Include all warnings
CFLAGS += -g # Generate GDB debugger information
CFLAGS += -Wno-strict-aliasing # Disable warnings about strict aliasing
CFLAGS += -Os # Optimize for size
CFLAGS += -DNDEBUG # Disable assert() macro
CFLAGS += -DEI_CLASSIFIER_ENABLE_DETECTION_POSTPROCESS_OP # Add TFLite_Detection_PostProcess operation

C++ only compiler flags

CXXFLAGS += -std=c++14 # Use C++14 standard

Linker flags

LDFLAGS += -lm # Link to math.h
LDFLAGS += -lstdc++ # Link to stdc++.h

Let me ask our embedded team for advice here,

Best

Eoin

Hi @lderani

I’m pretty sure the flag you will need to use when compiling to exclude our tflite is:

-DEI_CLASSIFIER_USE_FULL_TFLITE=0

Let me do some testing locally on one of the older G24 Silabs boards, I don’t have any of the Xiao ones :smiley:

Best

Eoin

Hi Eoin, thanks for the reply,

I tried to put the suggested flag directly inside the platform.txt file of the Silabs Arduino package, that controls how the compiler/linker/etc will build the sketch at:

C:\Users\Luis\AppData\Local\Arduino15\packages\SiliconLabs\hardware\silabs\3.0.0\platform.txt

...
build.extra_flags=

# Add the include list and the precompiled libraries for the selected board
compiler.silabs.flags={build.include_list}
compiler.silabs.precompiled_libs={build.precompiled_libs}
compiler.silabs.precompiled_gsdk={build.precompiled_gsdk}

# These can be overridden in platform.local.txt
compiler.c.extra_flags=-DEI_CLASSIFIER_USE_FULL_TFLITE=0
compiler.c.elf.extra_flags=
compiler.cpp.extra_flags=-DEI_CLASSIFIER_USE_FULL_TFLITE=0
compiler.S.extra_flags=
compiler.ar.extra_flags=
compiler.elf2bin.extra_flags=
compiler.elf2hex.extra_flags=
...

And confirmed at the log output that the compiler used the flag (heavily redacted to not waste space):

“C:\Users\Luis\AppData\Local\Arduino15\packages\SiliconLabs\tools\gcc-arm-none-eabi\12.2.rel1/bin/arm-none-eabi-gcc” -mcpu=cortex-m33 … -Os … “-DARDUINO_SILABS="3.0.0"” -DARDUINO_BOARD_XIAO_MG24 … -DARDUINO_SILABS_GECKO -DEI_CLASSIFIER_USE_FULL_TFLITE=0 … “C:\Users\Luis\AppData\Local\arduino\sketches\05E61CED255EDA90751A781933D93C90\libraries\MG24_Sense_inferencing\edge-impulse-sdk\CMSIS\NN\Source\ConvolutionFunctions\arm_convolve_s8.c.o.d” “c:\src\Arduino\libraries\MG24_Sense_inferencing\src\edge-impulse-sdk\CMSIS\NN\Source\ConvolutionFunctions\arm_convolve_s8.c” -o “C:\Users\Luis\AppData\Local\arduino\sketches\05E61CED255EDA90751A781933D93C90\libraries\MG24_Sense_inferencing\edge-impulse-sdk\CMSIS\NN\Source\ConvolutionFunctions\arm_convolve_s8.c.o”

but it still includes both TFLite libraries and throws the same errors.

What I did then, after finding where the duplicated files are inside the Edge Impulse library, and I know that is not right to do - just to see if it would compile - was deleting some source files from your library:

  1. Deleted all .ccp files from

C:\src\Arduino\libraries\MG24_Sense_inferencing\src\edge-impulse-sdk\tensorflow\lite\micro\kernels

leaving the .h files there;

  1. Deleted the file:

micro_log.cpp

from C:\src\Arduino\libraries\MG24_Sense_inferencing\src\edge-impulse-sdk\tensorflow\lite\micro (it was also being double included).

And the sketch compiled.

I know that is not by any means a permanent solution, but maybe it can give a hint of how to make it right - and permanent - for Arduino libraries generated for this MCU?

Thanks for the help!
Luis.

Hello, any progress on this? Until there’s a recommended working method to disable one of the tflite libraries, I don’t think it can be considered that Edge Impulse works with SiLabs boards - any for that matter, since all them derive their Arduino core from the same pre-compiled binary blob (gsdk.a) which has tflite included in it.

Any help will be appreciated!
Thanks, Luis.