Open
Description
Reproduction:
- Create a new blank ESP-IDF project for ESP32 Dev Module
- Modify the source code
src/main.c
to
#include "mbedtls/aes.h"
void app_main() {
mbedtls_aes_context ctx;
mbedtls_aes_init(&ctx);
}
3, Hit compile:
Linking .pio/build/esp32dev/firmware.elf
/home/max/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32dev/src/main.o:(.literal.app_main+0x0): undefined reference to `mbedtls_aes_init'
/home/max/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32dev/src/main.o: in function `app_main':
/home/max/temp/espidf_mbedtls_bug/src/main.c:6: undefined reference to `mbedtls_aes_init'
collect2: error: ld returned 1 exit status
*** [.pio/build/esp32dev/firmware.elf] Error 1
- Realize when looking at the verbose compile log, that when the mbedtls library is compiled, it does so with the flag
-DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\"
- Realize that this flag is not in the compiler invocation for the firmware files in
src/
. - Set source code to
#define MBEDTLS_CONFIG_FILE "mbedtls/esp_config.h"
#include "mbedtls/aes.h"
void app_main() {
mbedtls_aes_context ctx;
mbedtls_aes_init(&ctx);
}
--> it compiles thanks to the config file being correctly selected
Linking .pio/build/esp32dev/firmware.elf
Retrieving maximum program size .pio/build/esp32dev/firmware.elf
Checking size .pio/build/esp32dev/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 3.5% (used 11312 bytes from 327680 bytes)
Flash: [== ] 16.1% (used 169253 bytes from 1048576 bytes)
Building .pio/build/esp32dev/firmware.bin
esptool.py v4.2.1
Creating esp32 image...
Merged 2 ELF sections
Successfully created esp32 image.
============[SUCCESS] Took 7.62 seconds =============
Conclusion: "Something" is preventing the src/
files in the main PlatformIO projects from getting the critical macro for the mbedtls config file. This causes problems when calling some mbedtls functions which the actual config redefined to have other names.
See discussion in community topic.