Problem with linker and building for ESP32s2 using ESP-IDF

Hello,
so i have cloned that standalone inference on esp32 repository and integrated as described. I work with ESP-IDF(v5.2.2) extension in vscode. I am using esp32s2, tried to build it and it compiled but in last stage of building it stopped.(ninja: build stopped: subcommand failed). This is the message it gives me:

[1175/1177] Linking CXX executable NGPv1.elf
FAILED: NGPv1.elf
cmd.exe /C "cd . && C:\Users\mikae\.espressif\tools\xtensa-esp-elf\esp-13.2.0_20230928\xtensa-esp-elf\bin\xtensa-esp32s2-elf-g++.exe -mlongcalls  -fno-builtin-memcpy -fno-builtin-memset -fno-builtin-bzero -fno-builtin-stpcpy -fno-builtin-strncpy -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32S2=0 -Wl,--Map=C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/build/NGPv1.map -Wl,--no-warn-rwx-segments -fno-rtti -fno-lto -Wl,--gc-sections -Wl,--warn-common -T esp32s2.peripherals.ld -T esp32s2.rom.ld -T esp32s2.rom.api.ld -T esp32s2.rom.libgcc.ld -T esp32s2.rom.newlib-funcs.ld -T esp32s2.rom.newlib-data.ld -T esp32s2.rom.spiflash.ld -T memory.ld -T sections.ld @CMakeFiles\NGPv1.elf.rsp -o NGPv1.elf  && cd ."
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj):(.literal._ZN2ei8spectral7feature17spectral_analysisEPNS_9ei_matrixES3_fNS0_8filter_tEfhthfS3_[_ZN2ei8spectral7feature17spectral_analysisEPNS_9ei_matrixES3_fNS0_8filter_tEfhthfS3_]+0x24): undefined 
reference to `ei_calloc(unsigned int, unsigned int)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj):(.literal._ZN13flatten_class5printEv[_ZN13flatten_class5printEv]+0x14): undefined reference to `ei_printf(char const*, ...)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj):(.literal._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0x28): undefined reference to `ei_free(void*)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj):(.literal._ZL21fill_result_struct_i8PK10ei_impulseP19ei_impulse_result_tPaffb+0x8): undefined reference to `ei_printf_float(float)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj):(.literal._ZL22inference_tflite_setupP39ei_learning_block_config_tflite_graph_tPyP12TfLiteTensorS3_S3_S3_RSt10unique_ptrIvPFvPvEE+0x8): undefined reference to `ei_read_timer_us()'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj):(.literal._ZN2ei5numpy13software_rfftEPfS1_jj[_ZN2ei5numpy13software_rfftEPfS1_jj]+0x0): undefined reference to `ei_malloc(unsigned int)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj):(.literal._ZL20inference_tflite_runPK10ei_impulseP39ei_learning_block_config_tflite_graph_tyP12TfLiteTensorS5_S5_PhP19ei_impulse_result_tb+0x8): undefined reference to `ei_run_impulse_check_canceled()'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj):(.literal.app_main+0x8): undefined reference to `ei_sleep(long)'   
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj): in function `flatten_class::print()':
C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/ei_flatten.h:36:(.text._ZN13flatten_class5printEv[_ZN13flatten_class5printEv]+0x6): undefined reference to `ei_printf(char const*, ...)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/ei_flatten.h:38:(.text._ZN13flatten_class5printEv[_ZN13flatten_class5printEv]+0x16): undefined reference to `ei_printf(char const*, ...)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/ei_flatten.h:40:(.text._ZN13flatten_class5printEv[_ZN13flatten_class5printEv]+0x3b): undefined reference to `ei_printf(char const*, ...)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/ei_flatten.h:43:(.text._ZN13flatten_class5printEv[_ZN13flatten_class5printEv]+0x70): undefined reference to `ei_printf(char const*, ...)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj): in function `ei::spectral::filters::butterworth_lowpass(int, float, float, float const*, float*, unsigned int)':
C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:50:(.text._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0x70): undefined reference to `ei_calloc(unsigned int, unsigned int)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:51:(.text._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0x7c): undefined reference to `ei_calloc(unsigned int, unsigned int)' 
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:52:(.text._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0x88): undefined reference to `ei_calloc(unsigned int, unsigned int)' 
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:53:(.text._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0x94): undefined reference to `ei_calloc(unsigned int, unsigned int)' 
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:54:(.text._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0xa0): undefined reference to `ei_calloc(unsigned int, unsigned int)' 
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj):C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:55: more undefined references to `ei_calloc(unsigned int, unsigned int)' follow
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj): in function `ei::spectral::filters::butterworth_lowpass(int, float, float, float const*, float*, unsigned int)':
C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:68:(.text._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0x313): undefined reference to `ei_free(void*)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:68:(.text._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0x31b): undefined reference to `ei_free(void*)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:79:(.text._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0x323): undefined reference to `ei_free(void*)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:80:(.text._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0x32b): undefined reference to `ei_free(void*)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:81:(.text._ZN2ei8spectral7filtersL19butterworth_lowpassEiffPKfPfj+0x333): undefined reference to `ei_free(void*)'
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj):C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:82: more undefined references to `ei_free(void*)' follow
C:/Users/mikae/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cpp.obj): in function `ei::spectral::filters::butterworth_highpass(int, float, float, float const*, float*, unsigned int)':
C:/Users/mikae/OneDrive/Desktop/esp32-idf-projects/NGPv1/edge-impulse-sdk/dsp/spectral/filters.hpp:106:(.text._ZN2ei8spectral7filtersL20butterworth_highpassEiffPKfPfj+0x70): undefined reference to `ei_calloc(unsigned int, unsigned int)'

There are lot more simillar errors but i think they relate to same problem.

One thing i tried was changing target device to esp32. And it built successfully. Changed back and crashed.

I dont know what the reason is , maybe it needs other compiler path or something else idk. I aslo found this topic Problems runing and compiling for ESP32S3 - #2 by AIWintermuteAI which was simillar to my problem but didnt find any solution for my case. If anyone had same issue and can help, i would be grateful. Thanks in advance.

Hi, @mikaL !
We have something called porting layer in our SDK - it contains the implementations of the essential functions, e.g. malloc/free/printf and etc, that are platform specific.
ESP32-S2 is not officially supported by Edge Impulse, I personally have not tested it - but I presume it will work, as long as you use a compatible ESP IDF version (we use 4.4, I tested with 5.x as well).

We’re working on making issue you have experienced with porting layer absence more understandable to users - meanwhile, you can just add your board to ESP32 porting layer

In your downloaded Edge Impulse deployment go to edge-impulse-sdk/porting/ei_classifier_porting.h and change
#if ((defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S3)) && EI_PORTING_ZEPHYR == 0)
to
#if ((defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32S2)) && EI_PORTING_ZEPHYR == 0)

Let me know if that works!

1 Like

Hi,
thanks for your reply. I made change as you provided and it solved my problem.

1 Like