Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the cause of not being able to divide numbers in GCC

Tags:

c

gcc

makefile

arm

i'm having a very strange situation. Every time I try to compile my arm project (LPC2378, codesourcery arm-none-eabi-gcc-4.5.1) I am left with the same error whilst linking

/media/data/Projects/arm/uart/main.c:39: undefined reference to `__aeabi_uidiv'
/media/data/Projects/arm/uart/main.c:40: undefined reference to `__aeabi_uidiv'

The offending code looks like this:

U0DLL = ((((PLLCFG & 0x7FFF) + 1) * F_OSC) / ((((PLLCFG & (0xFF << 16)) >> 16) + 1) * ((CCLKCFG & 0xFF) + 1) * 8 * BAUD * 1)) % 256;
U0DLM = ((((PLLCFG & 0x7FFF) + 1) * F_OSC) / ((((PLLCFG & (0xFF << 16)) >> 16) + 1) * ((CCLKCFG & 0xFF) + 1) * 8 * BAUD * 1)) / 256;

I've searched around and what this can be caused by, AFAICT, not using lgcc & lc options for LD. I've resolved that and still the error remains.

The full project can be found at my github repo.

If anybody could help it would be greatly received. Cheers.

like image 729
regomodo Avatar asked Jul 04 '11 22:07

regomodo


3 Answers

The ARM family of CPUs does not have a native integer division instruction. So, division needs to be implemented by a library function. GCC knows this, and creates a reference to (in your case) __aeabi_uidiv (for unsigned int division).

You will need to link with an appropriate runtime support library that contains this function.

like image 132
Greg Hewgill Avatar answered Nov 15 '22 05:11

Greg Hewgill


I faced this issue and resolved it by passing the proper location of the libgcc.a in the Makefile. You may have to add:

"-L*path_to_libgcc.a* -lgcc" 

to LDFLAGS

like image 32
Balamurugan.A Avatar answered Nov 15 '22 07:11

Balamurugan.A


Sounds like a toolchain problem - perhaps your gcc is built for ARM EABI but your libraries (libgcc?) were built for traditional ABI?

like image 26
R.. GitHub STOP HELPING ICE Avatar answered Nov 15 '22 05:11

R.. GitHub STOP HELPING ICE