Linking against the math library

Pato
Posts: 27
Joined: Sat Mar 24, 2018 12:52 am

Linking against the math library

Postby Pato » Sat Mar 24, 2018 1:18 am

Hello,

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 (https://bbs.espressif.com/viewtopic.php ... 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 ? :)
Thx!

Pato
Posts: 27
Joined: Sat Mar 24, 2018 12:52 am

Re: Linking against the math library

Postby Pato » Fri Apr 06, 2018 10:02 pm

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.

Who is online

Users browsing this forum: No registered users and 8 guests