Page 1 of 1

Linking against the math library

Posted: Sat Mar 24, 2018 1:18 am
by Pato

I'm trying to build the blinky example where I added a simple cos() and included math.h, with a toolchain based on the esp-open-sdk toolchain, and using the ESP8266_NONOS_SDK-2.2.0.

However it fails at linking stage because of the cos() with errors like these:
.../xtensa-lx106-elf/lib/libm.a(lib_a-k_rem_pio2.o):(.literal+0x1c): undefined reference to '__gedf2'

I tried several linker flags as -lm, -lmirom, etc at various position, and even the libmirom.a from the RTOS SDK as suggested here ( ... math#p3254) but with same error. And according to this same post the math library IS implemented.

So, how do you link or use the math library ? :)

Re: Linking against the math library

Posted: Fri Apr 06, 2018 10:02 pm
by Pato
It appeared that I need to look recursively for the libraries in the linking command, ie to use "Wl" flag:

Code: Select all

[b]-Wl,[/b]--start-group -lmain -lnet80211 -lwpa -llwip -lpp -lphy -lhal -lc -lgcc -ldriver [b]-lm[/b] [b]-Wl,--end-group[/b]

Moreover, the fmod() and fmof() are relying by default on the the libgcc function _ieee754_remainder() which is not implemented by the XTensa compiler what break the compilation. To fix it, you can edit crosstool-NG/.build/src/newlib-2.0.0/newlib/libm/math/ef_fmod.c and change the #ifdef from 1 to 0 to enable the native version of fmod() that is independant from _ieee754_remainder() and recompile the SDK.

With this two fixes, I got a fully functionnal math library.