[En-Nut-Discussion] Multiple definition of free and malloc

Stephan Uhle stephan.uhle at alcatel.de
Tue Jun 14 09:48:47 CEST 2005


Hi Harald,

thanks for the immediate answer, unfortunately this doesn't work either.
Maybe I should have mentioned in my previous message that I got two 
additional warnings, saying that the sizes of the symbols free and malloc have
changed, but I think this belongs to the multiple definition errors.

Here is the complete error message I get:

~/avr/gcc/bin/../lib/gcc-lib/avr/3.3/../../../../avr/lib/avr5/libc.a(malloc.o)(.text+0x0):
In function `malloc':
~/avr/avr-libc-1.2.3/avr5/obj-avr/libc/stdlib/../../../../libc/stdlib/malloc.c:67: multiple definition of `malloc'
/cc/rbc/OMSDevelopment/TCB/stephan/nut/lib/libnutcrt.a(malloc.o)(.text+0x0): first defined here

~/avr/gcc/bin/../lib/gcc-lib/avr/3.3/../../../../avr/bin/ld: Warning: size of symbol `malloc' changed from 6 in 
~/nut/lib/libnutcrt.a(malloc.o) to 336 in ~/nut/lib/libnutcrt.a(malloc.o)

~/avr/gcc/bin/../lib/gcc-lib/avr/3.3/../../../../avr/lib/avr5/libc.a(malloc.o)(.text+0x150):
In function `free':
~/avr/avr-libc-1.2.3/avr5/obj-avr/libc/stdlib/../../../../libc/stdlib/malloc.c:190: multiple definition of `free'
/cc/rbc/OMSDevelopment/TCB/stephan/nut/lib/libnutcrt.a(malloc.o)(.text+0x6): first defined here

~/avr/gcc/bin/../lib/gcc-lib/avr/3.3/../../../../avr/bin/ld: Warning: size of symbol `free' changed from 6 in 
~/nut/lib/libnutcrt.a(malloc.o) to 198 in ~/nut/lib/libnutcrt.a(malloc.o)
*** Error code 1


the best solution I've got so far is:

avr-gcc -mmcu=atmega128 -Wl,--defsym=main=0,-Map=./obj/myprog.map,--cref -L~/nut/lib -nostdlib obj/*.o \
~/avr/gcc/avr/lib/avr5/crtm128.o ~/nut/lib/nutinit.o -lc -lgcc -lnutos -lnutcrt -lnutdev -lnutfs -lnutnet \
-lnutos -lnutpro -lnutcpp -lnutcrt -lc -o obj/myprog.elf

but I still get a "symbol size changed" message of `__iob' within 
libc.a(fdevopen.o) and libnutcrt.a(fopen.o) and due to this (I suppose so)
printf doesn't print out anything. :o/

I guess I have to go on and play around with the link order of the libraries.

thanks,

Stephan

At 12:22 13.06.2005 +0200, you wrote:
>Hi Stephan,
> 
>avr-gcc uses a one-pass linker. In some situations you have to
>add a lib twice. So, simply add -lnutcrt once more at the end
>of the list.
>
>Beside that, I tried to replace NutHeapAlloc/Free at several
>places in the kernel to make it look more familiar. Actually
>this wasn't a good idea. Now even app/simple needs to be linked
>to libnutcrt.a. I'll revert these changes. That doesn't mean,
>it should be replaced everywhere. For example, most modules
>in pro/ use libnutcrt.a anyway (printf etc.) and should prefer
>the standard functions (malloc/calloc/free).
>
>Harald
-- 




More information about the En-Nut-Discussion mailing list