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

11,830

Solution 1

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.

Solution 2

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

Solution 3

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

Share:
11,830
regomodo
Author by

regomodo

Updated on June 08, 2022

Comments

  • regomodo
    regomodo almost 2 years

    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.

  • regomodo
    regomodo almost 13 years
    From grepping the linked directory the appropriate library was being linked. It turns out it was the order of linking that caused the error as banthar pointed out.
  • Andrew Barber
    Andrew Barber over 11 years
    The link you have provided to your product website does not contain any information about the error in this question. It is not at all appropriate to include such unrelated links like this - especially when they are self-promotional. I am removing the link for you so your answer is not marked as spam.
  • David Belohrad
    David Belohrad over 11 years
    I though that the message at the web page is clear. i wrote it to myself because I encountered exactly the same problem but using different sources: 1) you get __aeabi_uidiv error when not linking to libgcc.a 2) libgcc.a is a part of codesourcery 3) it is stored in versioned directory 4) if your makefile hooks to incorrect version, it simply does not work. I'm not going to repeat here what I've written already elsewhere, thus the link. If you find it inappropriate, then let it be. (in fact I would delete the post, but it does not get deleted, it is just flaggedd)