cancel
Showing results for 
Search instead for 
Did you mean: 

Linker error when generating a project with tflite runtime and cmake build on STM32F7 Discovery

jjaccard
Associate II

Hello,

 

I am trying to build a simple AI app on my stm32f7 discovery board.

In VSCode when I try to build my cmake project (simple hello world DNN) generated with STM32CubeMX and TFlite Micro runtime (application template), I get a lot of linker errors:

 

[build] C:/ST/STM32CubeCLT_1.15.1/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: CMakeFiles/ai_app2_tfruntime.dir/X-CUBE-AI/App/app_x-cube-ai.c.obj: in function `ai_boostrap':

[build] C:/projects/ml/st_trials/ai_app2_tfruntime/X-CUBE-AI/App/app_x-cube-ai.c:77: undefined reference to `tflm_c_create'

[build] C:/ST/STM32CubeCLT_1.15.1/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/projects/ml/st_trials/ai_app2_tfruntime/X-CUBE-AI/App/app_x-cube-ai.c:87: undefined reference to `tflm_c_operators_size'

[build] C:/ST/STM32CubeCLT_1.15.1/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/projects/ml/st_trials/ai_app2_tfruntime/X-CUBE-AI/App/app_x-cube-ai.c:88: undefined reference to `tflm_c_tensors_size'

[...lots of other errors...]

All of them seem related to the declarations in tflm_c.h and the linker not finding the C++ definition in tflm_c.cc.

If I add tflm_c.cc as source (in cmake/stm32cubemx/CMakeLists.txt), I get a lot of other linker errors:

[build] C:/ST/STM32CubeCLT_1.15.1/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: CMakeFiles/ai_app2_tfruntime.dir/X-CUBE-AI/App/tflm_c.cc.obj: in function `AbortImpl()':

[build] C:/projects/ml/st_trials/ai_app2_tfruntime/cmake/stm32cubemx/../../Middlewares/tensorflow/tensorflow/lite/kernels/op_macros.h:25: undefined reference to `DebugLog'

[build] C:/ST/STM32CubeCLT_1.15.1/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: CMakeFiles/ai_app2_tfruntime.dir/X-CUBE-AI/App/tflm_c.cc.obj: in function `tflite::MicroErrorReporter::~MicroErrorReporter()':

[build] C:/projects/ml/st_trials/ai_app2_tfruntime/cmake/stm32cubemx/../../Middlewares/tensorflow/tensorflow/lite/micro/tflite_bridge/micro_error_reporter.h:28: undefined reference to `vtable for tflite::MicroErrorReporter'

[...lots of other errors...]

How can I solve this?

 

N-B: I use the toolchain that comes with CubeCLT version 1.15.1.

Thanks in advance, Best regards

 

Jérémie

 

 

 

 

 

 

 

1 REPLY 1
fauvarque.daniel
ST Employee

Here is what worked for me 

Create a project with STM32CubeMX 6.12 add AI, your tflite network and select tflite runtime

Go to the Project Manager tab, enter a project name and select "cmake" as IDE

Generate code

in the generated folder edit cmake/stm32cubemx/CMakeLists.txt

replace all  ../../../ by ../../

Add all the missing c++ files in target_sources (all the files ending with .cc) it should be in the form of 

../../Middlewares/tensorflow/tensorflow/lite/core/api/error_reporter.cc

for example if you are in a shell you can do

$ cd cmake/stm32cubemx/

$ find ../.. -name \*.cc >out

and them add the content of out into the target_sources

add the path of arm-none-eabi-gcc to your PATH

then lauch cmake and make

cmake CMakeLists.txt

make

Regards


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.