Linking math library into the project

mikkojaakkola
Posts: 5
Joined: Fri Aug 02, 2019 3:03 am

Linking math library into the project

Postby mikkojaakkola » Tue Aug 13, 2019 2:12 am

I'm trying to link 3rd party library (no source code available) that's compiled for ESP32 but it uses a set of math library functions like roundf, fmaxf, sinf, ...

I see these implemented as special functions accessed through macros in fastmath.h but, of course, they cannot be used as they don't materialize into binaries with the symbols to enable linking to the library that's not obviously using those functions.

I'm using ESP-IDF 4.0. Any tips how to make progress?

mikkojaakkola
Posts: 5
Joined: Fri Aug 02, 2019 3:03 am

Re: Linking math library into the project

Postby mikkojaakkola » Tue Aug 13, 2019 3:53 pm

I did more investigation and by manually linking libm.a, I resolved most of the issues. Shouldn't this be part of the linking process by default as linker would remove all the functions that are not being used anyway?

add_library(mathlib STATIC IMPORTED GLOBAL)
set_target_properties(mathlib PROPERTIES IMPORTED_LOCATION "...../libm.a")
target_link_libraries(${COMPONENT_LIB} PUBLIC mathlib)

The only unresolved functions left are:
libm.a(lib_a-wf_sqrt.o):(.literal+0x4): undefined reference to `__ieee754_sqrtf'
libm.a(lib_a-ef_pow.o): in function `__ieee754_powf'

Would anybody happen to know where I could find them? I'm sure they are buried somewhere in the newlib libraries.

Who is online

Users browsing this forum: doragasu, ferrero, forrest and 141 guests