EmbeddedRelated.com
Forums

problems using math.h

Started by oemtyo August 12, 2005
Hi everyone,

I'm programming an application for lpc2119 and need to do
complex mathematical calculations with values got from the
A/D-Converter. Therefore i need to include the math.h to be
able to call functions such as pow() or sqrt() ...

The linker-flag "-lm" to include the math-library is set.
(GNU ld version 2.14 20030612)

But using newlib version 1.12.0 and arm-elf-gcc 3.3.3 I get
several linker errors with undefined references to functions
the libm.a should provide.

<snip>
make -k all
arm-elf-ld -v -omain.prg ./crt0.o smon_main.o armVIC.o printf.o
-T./lpc2119.ld -Map map
/home/lpc2119/arm-elf/arm-elf/lib/libm.a(w_pow.o)(.text+0x80): In
function `pow':
/home/lpc2119/newlib-1.12.0/newlib/libm/math/w_pow.c:88: undefined
reference to `__eqdf2'
/home/lpc2119/arm-elf/bin/../arm-elf/lib/libm.a(w_
pow.o)(.text+0x128):/home/lpc2119/newlib-1.12.0/ne
wlib/libm/math/w_pow.c:108:
undefined reference to `__eqdf2'
[...] 8 lines more
/home/lpc2119/arm-elf/bin/../arm-elf/lib/libm.a(e_pow.o)(.text+0x4c8):
In function `__ieee754_pow':
/home/lpc2119/newlib-1.12.0/newlib/libm/math/e_pow.c:271: undefined
reference to `__gtdf2'
/home/lpc2119/arm-elf/bin/../arm-elf/lib/libm.a(e_
pow.o)(.text+0x98c):/home/lpc2119/newlib-1.12.0/ne
wlib/libm/math/e_pow.c:277:
undefined reference to `__ledf2'
[...] 4 lines more
In function `__ieee754_sqrt':
/home/lpc2119/newlib-1.12.0/newlib/libm/math/e_sqrt.c:180: undefined
reference to `__gtdf2'
GNU ld version 2.14 20030612
make: *** [main.prg] Errors 1
make: Target all not compiled due to errors.
</snip>

Any idea on fixing this?

Thanks in advance.

Markus Plessing



An Engineer's Guide to the LPC2100 Series

I had similar problems. Then I changed the order of my linker flags
(and even duplicated them like: "-lm -lc -lgcc -lstdc++ -lm")...and it
worked. Good Luck!
Matthias
--- In lpc2000@lpc2..., "oemtyo" <plessing@e...> wrote:
> Hi everyone,
>
> I'm programming an application for lpc2119 and need to do
> complex mathematical calculations with values got from the
> A/D-Converter. Therefore i need to include the math.h to be
> able to call functions such as pow() or sqrt() ...
>
> The linker-flag "-lm" to include the math-library is set.
> (GNU ld version 2.14 20030612)
>
> But using newlib version 1.12.0 and arm-elf-gcc 3.3.3 I get
> several linker errors with undefined references to functions
> the libm.a should provide.
>
> <snip>
> make -k all
> arm-elf-ld -v -omain.prg ./crt0.o smon_main.o armVIC.o printf.o
> -T./lpc2119.ld -Map map
> /home/lpc2119/arm-elf/arm-elf/lib/libm.a(w_pow.o)(.text+0x80): In
> function `pow':
> /home/lpc2119/newlib-1.12.0/newlib/libm/math/w_pow.c:88: undefined
> reference to `__eqdf2'
> /home/lpc2119/arm-elf/bin/../arm-elf/lib/libm.a(w_
> pow.o)(.text+0x128):/home/lpc2119/newlib-1.12.0/ne
> wlib/libm/math/w_pow.c:108:
> undefined reference to `__eqdf2'
> [...] 8 lines more
> /home/lpc2119/arm-elf/bin/../arm-elf/lib/libm.a(e_pow.o)(.text+0x4c8):
> In function `__ieee754_pow':
> /home/lpc2119/newlib-1.12.0/newlib/libm/math/e_pow.c:271: undefined
> reference to `__gtdf2'
> /home/lpc2119/arm-elf/bin/../arm-elf/lib/libm.a(e_
> pow.o)(.text+0x98c):/home/lpc2119/newlib-1.12.0/ne
> wlib/libm/math/e_pow.c:277:
> undefined reference to `__ledf2'
> [...] 4 lines more
> In function `__ieee754_sqrt':
> /home/lpc2119/newlib-1.12.0/newlib/libm/math/e_sqrt.c:180: undefined
> reference to `__gtdf2'
> GNU ld version 2.14 20030612
> make: *** [main.prg] Errors 1
> make: Target all not compiled due to errors.
> </snip>
>
> Any idea on fixing this?
>
> Thanks in advance.
>
> Markus Plessing



--- In lpc2000@lpc2..., "wiese_matthias" <wiese_matthias@y...>
wrote:
> I had similar problems. Then I changed the order of my linker flags
> (and even duplicated them like: "-lm -lc -lgcc -lstdc++ -lm")...and it
> worked. Good Luck!
> Matthias

Thanks Matthias, this change made the thing ...

But:

Is lpc2119 able to do this sort of floating point operations?

At the moment my app is stopping at the point pow() is used
and the extern watchdog is rebooting.

Thanks

Markus Plessing