Skip to content

undefined reference to `MD5Update' in arduino as component #5925

Closed
@qt1

Description

@qt1

The compilation of a project referencing MD5Builder fails link with undefined reference to `MD5Update'

Creating a minimal project with this error:

  1. Latest ESP-IDF, install.sh and export.sh

  2. Create new project using

     idf.py create-project proj1
     cd proj1
    

At this point the project compiles.

  1. Add arduino-esp32 as in the docs

     mkdir -p components && \
     cd components && \
     git clone https://github.com/espressif/arduino-esp32.git arduino && \
     cd arduino && \
     git submodule update --init --recursive && \
     cd ../.. && \
     idf.py menuconfig
    
  2. Rename 'proj1.c' to 'proj1.cpp' and change in 'CMakeList.txt', content from docs. At this point the project still compiles

  3. Add reference to 'MD5Builder.h' like so: (based on the example in the docs)

     //file: proj1.cpp
     #include "Arduino.h"
     
     #include "MD5Builder.h"
     
     void setup(){
         Serial.begin(115200);
     
         MD5Builder hasher;
         hasher.add("hello");
         Serial.println( hasher.toString());
     }
     
     void loop(){
         Serial.println("loop");
         delay(1000);
     }
     
     extern "C" {
     void app_main(void)
     {
         setup();
         while(1)
             loop();
     }
     }
    

Now the compilation fails with linker error:

    ../components/arduino/cores/esp32/MD5Builder.cpp:37: undefined reference to `MD5Update'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    ninja failed with exit code 1

Please advise.

Activity

atanisoft

atanisoft commented on Nov 24, 2021

@atanisoft
Collaborator

arduino-esp32 master (assuming that is what you are using since you didn't specify) only supports ESP-IDF v4.4 and not earlier. You state "Latest ESP-IDF" but that doesn't indicate what version you are using.

qt1

qt1 commented on Nov 24, 2021

@qt1
ContributorAuthor

This happens with multiple matching versions of esp-idf and arduino-esp32.

Specifically the latest versions are:
components/arduino 399f4ec
esp-idf ddc44956bf718540d5451e17e1becf6c7dffe5b8

MD5Update is a C function that may also be available in the ROM, but I don't know.

I suspect that there is a linker setting or some flag that is needed in the the CMakeList.txt', or maybe some additional flag in some configuration file.

I would appreciate if someone that knows the system could look and help with this.

Thanks

atanisoft

atanisoft commented on Nov 24, 2021

@atanisoft
Collaborator

which specific ESP32 target are you using via idf.py?

qt1

qt1 commented on Nov 25, 2021

@qt1
ContributorAuthor

The target is esp32 (default). Same result when the target explicitly using idf.py set-target esp32 .

atanisoft

atanisoft commented on Nov 28, 2021

@atanisoft
Collaborator

@qt1 Try disabling CONFIG_WPA_MBEDTLS_CRYPTO in your sdkconfig. It looks like when this is enabled there is no actual implementation compiled of the various MD5 functions that are used currently by MD5Builder.

The PR below fixes the issue so it doesn't depend on sdkconfig entries.

qt1

qt1 commented on Nov 28, 2021

@qt1
ContributorAuthor

According to some other issues referencing MD5Update

Adding the following to esp-idf/components/esp_rom/esp32/ld/esp32.rom.ld seems to solve the problem.

    PROVIDE ( MD5Final = 0x4005db1c );
    PROVIDE ( MD5Init = 0x4005da7c );
    PROVIDE ( MD5Update = 0x4005da9c );

I is possible that theses where left out for a reason, so I m not sure if I should PR esp-idf or not..

Setting CONFIG_WPA_MBEDTLS_CRYPTO=n also solves the linker error. (I guess the first option uses ROM implementation and the other uses compiled version)

Thanks!

atanisoft

atanisoft commented on Nov 28, 2021

@atanisoft
Collaborator

Those entries are intentionally omitted from the ld scripts as they used to be provided by the WPA code, as part of migrating to ESP-IDF v4.4 though this became optionally compiled based on CONFIG_WPA_MBEDTLS_CRYPTO. The PR I've created migrates to the underlying ROM APIs which are available on all targets.

qt1

qt1 commented on Nov 28, 2021

@qt1
ContributorAuthor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      undefined reference to `MD5Update' in arduino as component · Issue #5925 · espressif/arduino-esp32