EmbDev.net

Forum: ARM programming with GCC/GNU tools math.h & newlib & MacOSX(Intel) toolsuite


von Jim C. (jimclark)


Rate this post
useful
not useful
Using GNU Cross Compiler Tools, on MacBook Pro (Intel host).
arm-elf-gcc toolsuite with newlib downloaded from:
http://www.mikrocontroller.net/articles/ARM_GCC_toolchain_for_Linux_and_Mac_OS_X

I am having trouble with adding math functions (like sin using "math.h"
and using -lm in my linker with this toolset.

I am new to newlib and am not sure if i need to download an include
directory with this toolchain, or if I just need to link against -lm

I seem to get the following errors:

JimMacBookPro:~/Desktop/umon/umon_apps/user_manual jamessclarkiv$ make
clean
rm -f *.o app[1-5] app[1-5].dis app[1-5].sym symtbl
JimMacBookPro:~/Desktop/umon/umon_apps/user_manual jamessclarkiv$ make
app2
arm-elf-gcc -fno-builtin -mcpu=arm9tdmi -c -Wall -O -g -I. -o crt0_arm.o
crt0_arm.S
arm-elf-gcc -fno-builtin -mcpu=arm9tdmi -c -Wall -O -g -I. -D
MONCOMPTR=0x10000020 -o main2.o main2.c
main2.c: In function 'main':
main2.c:24: warning: assignment from incompatible pointer type
main2.c:28: warning: implicit declaration of function 'sin'
arm-elf-gcc -fno-builtin -mcpu=arm9tdmi -c -Wall -O -g -I. -o monlib.o
monlib.c
monlib.c: In function 'mon_xcrc16':
monlib.c:733: warning: pointer targets in passing argument 1 of
'_xcrc16' differ in signedness
arm-elf-ld -e start -o app2 -Ttext 0x20100000 crt0_arm.o main2.o
monlib.o /usr/local/arm/lib/gcc/arm-elf/4.1.0/libgcc.a
/usr/local/arm/arm-elf/lib/libm.a
/usr/local/arm/arm-elf/lib/libm.a(s_sin.o): In function `sin':
../../../.././newlib/libm/math/s_sin.c:117: undefined reference to
`__subdf3'
/usr/local/arm/arm-elf/lib/libm.a(e_rem_pio2.o): In function
`__ieee754_rem_pio2':
../../../.././newlib/libm/math/e_rem_pio2.c:166: undefined reference to
`__subdf3'
../../../.././newlib/libm/math/e_rem_pio2.c:104: undefined reference to
`__subdf3'
../../../.././newlib/libm/math/e_rem_pio2.c:106: undefined reference to
`__subdf3'
../../../.././newlib/libm/math/e_rem_pio2.c:107: undefined reference to
`__subdf3'
/usr/local/arm/arm-elf/lib/libm.a(e_rem_pio2.o):../../../.././newlib/lib 
m/math/e_rem_pio2.c:107:
more undefined references to `__subdf3' follow
/usr/local/arm/arm-elf/lib/libm.a(e_rem_pio2.o): In function
`__ieee754_rem_pio2':
../../../.././newlib/libm/math/e_rem_pio2.c:129: undefined reference to
`__muldf3'
../../../.././newlib/libm/math/e_rem_pio2.c:129: undefined reference to
`__adddf3'
../../../.././newlib/libm/math/e_rem_pio2.c:129: undefined reference to
`__fixdfsi'
../../../.././newlib/libm/math/e_rem_pio2.c:130: undefined reference to
`__floatsidf'
../../../.././newlib/libm/math/e_rem_pio2.c:131: undefined reference to
`__muldf3'

etc.

Only change to the working makefile above was linking against libm.a and
libgcc.a and adding a single sin() call to my main() and including
<math.h> in main.

The ../../../.././newlib etc directories do not seem to exist on my
system??

Thanks in advance for any help.

Best regards,
Jim Clark

von Darrik Spaude (Guest)


Rate this post
useful
not useful
> Only change to the working makefile above was linking against libm.a and
> libgcc.a and adding a single sin() call to my main() and including
> <math.h> in main.
>
> The ../../../.././newlib etc directories do not seem to exist on my
> system??

I wonder if the "--with-float=soft" option might have anything to do
with this (but I'm very unfamiliar with the source code and compile-time
options). Are you able to build your code on another platform and it
works? If so, what are all of the source version numbers (newlib 1.17,
gcc 4.1.1, etc.) for the working platform.

I can try to look at the source code for newlib or wherever the
undefined functions are found and see if there is some option that needs
to be used. I could also try to build a couple versions of the toolchain
and see which one works for you.

Darrik

von Darrik S. (dspaude)


Rate this post
useful
not useful
Hello Jim,

I compiled a version of the ARM7 toolchain for Intel Mac with
--with-float=soft. I don't know if it will resolve your problem. I
noticed you are using an ARM9 mpu (arm9tdmi), so I don't know if this
ARM7 toolchain will work out for you. I have a dial-up connection, so I
cannot upload the toolchain at the moment, but I'll let you know when it
is up and where.

If you would like to try to modify the compiling scripts and t-arm-elf
to support ARM9, then let me know.

Best Regards,
Darrik

von Jim C. (jimclark)


Rate this post
useful
not useful
I was able to get it working by simply switching the order of the libs
included in the ld call line.

app2: varcheck $(OBJS2) makefile
  $(LD) -e start -o app2 -Ttext $(APPRAMBASE) $(OBJS2)
/usr/local/arm/arm-elf/lib/libm.a /usr/local/arm/arm-elf/lib/libc.a
/usr/local/arm/lib/gcc/arm-elf/4.1.0/libgcc.a
  $(NM) --numeric-sort app2 >app2.sym
  $(OBJDUMP) --source --disassemble app2 > app2.dis

The above call works. I believe libgcc needs to be last or libc needs to
be before libgcc or something. I found this suggestion on the
sparkfunelectronics arm forum.

It seemed to solve my problem. FYI, the floats work and the code works
on the arm9.

As I understand it, when calling the linker (ld) directly as opposed to
having gcc call it for you, you don't get as simple lib search path
resloving. So I just specified all libs directly and it seemed to work.

Best regards, and thanks for taking the time to follow up.
Jim Clark

von Darrik S. (dspaude)


Rate this post
useful
not useful
Thank, Jim. I'll still post my updated version of the toolchain later
this week.

Darrik

von Darrik Spaude (Guest)


Rate this post
useful
not useful
I posted the GCC 4.2.0 toolchain (PPC and Intel) to my web site's blog
section:

http://spaudemedia.com/blogs/blog_20070704_ARM7Toolchain04.html

Darrik

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.