EmbeddedRelated.com
Forums

GCC library linker problems

Started by Eric Fattah February 20, 2007
I am developing firmware for a custom LPC2138 board, using GNUARM/Eclipse. The project is at an advanced stage, nearing completion.

I am using custom start up code, and a custom linker script. However, the entire project must run as a 'managed make' under the Eclipse GUI. I am not allowed to create stand alone makefiles. As I mentioned, I have a very effective code running on the target board. Only recently did I run into linker problems.

When trying to add certain library functions such as sprintf, or trying to do an integer division, or certain (but not all) floating point functions such as cos(), I get a huge list of undefined references.

I have set the linker to -lc -lm -lg, to use those libraries.
But, I have -nostartfiles, -nostdlib. However I do allow default libs.

If I allow the standard startfiles & libraries, the undefined references vanish, but then I get all sorts of errors based on the double defined items in the startup code & linker scripts. Clearly I cannot allow the compiler to attempt to use its own startup and linker files. So I need to find a way to resolve the references and link the appropriate libraries WITHOUT allowing the compiler to use standard startup and linker files.

I have been trying to solve this problem for days, I searched the web and the archives, without any success.

I have pasted the build output below, for an example where I try an integer division. Any help would be greatly appreciated.

Eric
______________

**** Build of configuration Release for project X1_Core ****

make -k all
'Building file: ../bsp.c'
'Invoking: GCC C Compiler'
arm-none-eabi-gcc -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"bsp.d" -MT"bsp.d" -o"bsp.o" "../bsp.c"
In file included from ../x1.h:38,
from ../bsp.c:1:
../irda.h:7:7: warning: no newline at end of file
'Finished building: ../bsp.c'
' '
'Building target: X1_Core.o'
'Invoking: GCC C Linker'
arm-none-eabi-gcc -nostartfiles -nostdlib ../boot.o ../x1_isr.o -lc -Xlinker --script=../lpc2138.ld -o"X1_Core.o" ./MS5541.o ./UserSettings.o ./accel.o ./bsp.o ./flashmem.o ./globaldata.o ./graphics.o ./input_output.o ./irda.o ./mag.o ./main.o ./menu.o ./oled.o ./pressure.o ./rtc.o ./sleep.o ./spim_1.o ./spim_2.o ./taps.o ./utilities.o -lc -lg -lm
./bsp.o: In function `BSP_Timer0_ConfigureFreq':
bsp.c:(.text+0x498): undefined reference to `__aeabi_uidiv'
collect2: ld returned 1 exit status
make: *** [X1_Core.o] Error 1
make: Target `all' not remade because of errors.
Build complete for project X1_Core

An Engineer's Guide to the LPC2100 Series

Hi Eric,

Looks like you are missing libgcc.a from the list of libraries.
If you use "-nostartfiles -nostdlib" you have to add -lgcc to
get the integer division and other gcc helper functions.

elektrknight
---------------------
http://www.hbbrbasic.com/ Embedded IDE and BASIC Compiler
for ARM based microcontrollers
I added -lgcc and it fixed the uidiv problem, but all the other undefined references still occur. Below is a sample.

Eric

_____________

'Building target: X1_Core.o'
'Invoking: GCC C Linker'
arm-none-eabi-gcc -nostartfiles -nostdlib ../boot.o ../x1_isr.o -lc -Xlinker --script=../lpc2138.ld -Xlinker -lc -Xlinker -lm -Xlinker -lg -o"X1_Core.o" ./MS5541.o ./UserSettings.o ./accel.o ./bsp.o ./flashmem.o ./globaldata.o ./graphics.o ./input_output.o ./irda.o ./mag.o ./main.o ./menu.o ./oled.o ./operation.o ./pressure.o ./rtc.o ./sleep.o ./spim_1.o ./spim_2.o ./taps.o ./utilities.o -lgcc -lc -lm -lg
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(vfprintf.o): In function `_vfprintf_r':
vfprintf.c:(.text+0xa34): undefined reference to `__aeabi_dcmplt'
vfprintf.c:(.text+0xfac): undefined reference to `__aeabi_dcmpeq'
vfprintf.c:(.text+0x114c): undefined reference to `__aeabi_dcmpeq'
vfprintf.c:(.text+0x151c): undefined reference to `__aeabi_uldivmod'
vfprintf.c:(.text+0x1538): undefined reference to `__aeabi_uldivmod'
vfprintf.c:(.text+0x1c3c): undefined reference to `__aeabi_dcmpeq'
vfprintf.c:(.text+0x202c): undefined reference to `__aeabi_dcmpeq'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(dtoa.o): In function `_dtoa_r':
dtoa.c:(.text+0x2a8): undefined reference to `__aeabi_dcmpeq'
dtoa.c:(.text+0x354): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0x360): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x36c): undefined reference to `__aeabi_dadd'
dtoa.c:(.text+0x37c): undefined reference to `__aeabi_i2d'
dtoa.c:(.text+0x388): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x39c): undefined reference to `__aeabi_dadd'
dtoa.c:(.text+0x3a8): undefined reference to `__aeabi_d2iz'
dtoa.c:(.text+0x3c0): undefined reference to `__aeabi_dcmplt'
dtoa.c:(.text+0x3fc): undefined reference to `__aeabi_dcmplt'
dtoa.c:(.text+0x544): undefined reference to `__aeabi_ui2d'
dtoa.c:(.text+0x600): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x62c): undefined reference to `__aeabi_ddiv'
dtoa.c:(.text+0x658): undefined reference to `__aeabi_dcmplt'
dtoa.c:(.text+0x6a8): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x6b8): undefined reference to `__aeabi_i2d'
dtoa.c:(.text+0x6cc): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x6dc): undefined reference to `__aeabi_dadd'
dtoa.c:(.text+0x73c): undefined reference to `__aeabi_i2d'
dtoa.c:(.text+0x748): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x758): undefined reference to `__aeabi_dadd'
dtoa.c:(.text+0x7a4): undefined reference to `__aeabi_ddiv'
dtoa.c:(.text+0x7b0): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0x7cc): undefined reference to `__aeabi_d2iz'
dtoa.c:(.text+0x7d4): undefined reference to `__aeabi_i2d'
dtoa.c:(.text+0x7e8): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0x810): undefined reference to `__aeabi_dcmpgt'
dtoa.c:(.text+0x830): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0x844): undefined reference to `__aeabi_dcmpgt'
dtoa.c:(.text+0x85c): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0x868): undefined reference to `__aeabi_dcmplt'
dtoa.c:(.text+0x898): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x8b8): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x8c4): undefined reference to `__aeabi_d2iz'
dtoa.c:(.text+0x8cc): undefined reference to `__aeabi_i2d'
dtoa.c:(.text+0x8e0): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0x8fc): undefined reference to `__aeabi_dcmplt'
dtoa.c:(.text+0x998): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x9ac): undefined reference to `__aeabi_dcmpeq'
dtoa.c:(.text+0x9c8): undefined reference to `__aeabi_ddiv'
dtoa.c:(.text+0x9cc): undefined reference to `__aeabi_d2iz'
dtoa.c:(.text+0x9d4): undefined reference to `__aeabi_i2d'
dtoa.c:(.text+0x9e8): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x9fc): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0xa24): undefined reference to `__aeabi_dadd'
dtoa.c:(.text+0xa40): undefined reference to `__aeabi_dcmplt'
dtoa.c:(.text+0xa5c): undefined reference to `__aeabi_dcmpeq'
dtoa.c:(.text+0xcd4): undefined reference to `__aeabi_ddiv'
dtoa.c:(.text+0xd00): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0xd14): undefined reference to `__aeabi_dcmpgt'
dtoa.c:(.text+0xd38): undefined reference to `__aeabi_dcmplt'
dtoa.c:(.text+0xe74): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0xe80): undefined reference to `__aeabi_dcmpge'
dtoa.c:(.text+0x1000): undefined reference to `__aeabi_i2d'
dtoa.c:(.text+0x1014): undefined reference to `__aeabi_dcmpeq'
dtoa.c:(.text+0x12bc): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x12d0): undefined reference to `__aeabi_d2iz'
dtoa.c:(.text+0x12d8): undefined reference to `__aeabi_i2d'
dtoa.c:(.text+0x12ec): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0x1324): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x1330): undefined reference to `__aeabi_d2iz'
dtoa.c:(.text+0x1338): undefined reference to `__aeabi_i2d'
dtoa.c:(.text+0x134c): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0x138c): undefined reference to `__aeabi_dadd'
dtoa.c:(.text+0x1398): undefined reference to `__aeabi_dcmplt'
dtoa.c:(.text+0x13b8): undefined reference to `__aeabi_dsub'
dtoa.c:(.text+0x13c4): undefined reference to `__aeabi_dcmpgt'
dtoa.c:(.text+0x141c): undefined reference to `__aeabi_dmul'
dtoa.c:(.text+0x1454): undefined reference to `__aeabi_dmul'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(makebuf.o): In function `__smakebuf':
makebuf.c:(.text+0xe8): undefined reference to `isatty'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(mprec.o): In function `_ratio':
mprec.c:(.text+0x2f8): undefined reference to `__aeabi_ddiv'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(mprec.o): In function `_mprec_log10':
mprec.c:(.text+0x348): undefined reference to `__aeabi_dmul'
mprec.c:(.text+0x360): undefined reference to `__aeabi_dmul'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0x1c): undefined reference to `_sbrk'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(writer.o): In function `_write_r':
writer.c:(.text+0x24): undefined reference to `_write'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(closer.o): In function `_close_r':
closer.c:(.text+0x1c): undefined reference to `_close'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(fstatr.o): In function `_fstat_r':
fstatr.c:(.text+0x20): undefined reference to `_fstat'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(lseekr.o): In function `_lseek_r':
lseekr.c:(.text+0x24): undefined reference to `_lseek'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(readr.o): In function `_read_r':
readr.c:(.text+0x24): undefined reference to `_read'
collect2: ld returned 1 exit status
make: *** [X1_Core.o] Error 1
make: Target `all' not remade because of errors.
Build complete for project X1_Core
What happens if you use -nostartfiles, and leave out -nostdlib
(allowing the standard libs)?

Mike
> What happens if you use -nostartfiles, and leave out -nostdlib
> (allowing the standard libs)?
>
> Mike

_________________________________

This is what happens with -nostartfiles, but with stdlibs enabled:

**** Build of configuration Release for project X1_Core ****

make -k all
'Building target: X1_Core.o'
'Invoking: GCC C Linker'
arm-none-eabi-gcc -nostartfiles ../boot.o ../x1_isr.o -lc -Xlinker --script=../lpc2138.ld -Xlinker -lc -Xlinker -lm -Xlinker -lg -o"X1_Core.o" ./MS5541.o ./UserSettings.o ./accel.o ./bsp.o ./flashmem.o ./globaldata.o ./graphics.o ./input_output.o ./irda.o ./mag.o ./main.o ./menu.o ./oled.o ./operation.o ./pressure.o ./rtc.o ./sleep.o ./spim_1.o ./spim_2.o ./taps.o ./utilities.o -lgcc -lc -lm -lg
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/bin/ld.exe:rdimon-ram.ld:13: warning: redeclaration of memory region 'ram'
../boot.o: In function `_start':
(.text+0x18): multiple definition of `_start'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\rdimon-crt0.o:/scratch/paul/arm/src/newlib-20060320/libgloss/arm/crt0.S:(.text+0x0): first defined here
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/bin/ld.exe: section .data [00008000 -> 00008973] overlaps section prog [00000048 -> 00019e43]
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(init.o): In function `__libc_fini_array':
init.c:(.text+0x38): undefined reference to `_fini'
c:/program files/codesourcery/sourcery g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-eabi/lib\libc.a(init.o): In function `__libc_init_array':
init.c:(.text+0x84): undefined reference to `_init'
collect2: ld returned 1 exit status
make: *** [X1_Core.o] Error 1
make: Target `all' not remade because of errors.
Build complete for project X1_Core
> ../boot.o: In function `_start':
> (.text+0x18): multiple definition of `_start'
> c:/program files/codesourcery/sourcery
> g++/bin/../lib/gcc/arm-none-eabi/4.1.1/../../../../arm-none-ea
> bi/lib\rdimon-crt0.o:/scratch/paul/arm/src/newlib-20060320/lib
> gloss/arm/crt0.S:(.text+0x0): first defined here

The curious part is the line above that references rdimon-crt0.o. This
shouldn't be linked in, as it is startup code. Is there something special
in your boot.o that prevents you from using crt0.o? Perhaps if you call
boot.0 crt0.o it will work (this is what is done in my makefile, but I use
the WinARM toolchain).

This looks like it might be coming from newlib. I checked my sources for
newlib, and indeed, crt0.S is present there. I alas, don't use newlib,
so I haven't run into this yet. Perhaps you can leave the startup code
out of the makefile for newlib.

You mentioned earlier that you had this compiling fine. What is different
now?

Mike
Another question, which file contains your startup code?

Mike