esp-rs / esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
https://docs.esp-rs.org/esp-hal/
Apache License 2.0
725 stars 201 forks source link

multiple definition of malloc, calloc, and free when used together with other crates providing them #1618

Closed noahbliss closed 3 months ago

noahbliss commented 7 months ago

Hey! I use another crate which wraps some C code. That crate and esp-wifi both seem to rely on the C functions listed in the title. When both crates are used, the compiler dies of an aneurysm. Any ideas on possible solutions? Could this be added as a feature perhaps where a user can bring their own implementations of these functions? I'll request the same behavior from the other crate's maintainer.

Very simply, using the a121-rs crate and esp-wifi together doesn't work.

noahbliss commented 7 months ago

My noobish recommendation would be to make a default-enabled feature which enables these functions inside the crate, but that users can opt-out of if they have implemented them inside their own parent project.

bjoernQ commented 7 months ago

Just not including those functions is technically possible but where does the other crate place the heap? How does the heap get configured? The wifi drivers need a good chunk of memory (by default we reserve 64k but for some configurations more is needed)

noahbliss commented 7 months ago

I'm using a global allocation heap with esp-alloc in my main project. A121-rs is "bring your own heap", embedded alloc can also serve the same function more generically.

bjoernQ commented 3 months ago

I don't see where that library implements malloc and free - they are depending on these functions to be present here: https://github.com/Ragarnoy/a121-rs/blob/1d5453267be450a30104def8ac3efe35da6fd840/src/hal.rs#L133-L136

The examples however seem to use tinyrlibc which define those symbols - probably you need to not add this as a dependency