gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > undefined reference to `memcpy'

#21188 - cosmic4z - Tue May 25, 2004 4:51 pm

HELP !!! (please)

I am using devkit advance (GCC) .. and wish to have a string created in GBA ram .. my function looks like this :-

void SE_InitSI(sSI* pSI,sInitSI* pInitSI)
{
char cName[8] = {"hello"};

some code here ...
}

when I complie / link ... i get :-

SE.o: In function `SE_InitSI':
/cygdrive/e/dev/gba/cayho/SE.c:28: undefined reference to `memcpy'
/cygdrive/e/dev/gba/cayho/SE.c:28: undefined reference to `memset'
make: *** [main.elf] Error 1

are memcpy / memset in some library somewhere !?

what am I missing !?

Jamie
_________________
Qwak - www.qwak.co.uk | Forum - www.qwak.co.uk/forum/

#21189 - poslundc - Tue May 25, 2004 5:02 pm

I have the same problem in my version of GCC/DKA when trying to do anything that requires memcpy. You can circumvent the problem by doing it yourself: declare your string in the global scope as a const (make it static if you don't want to create extra symbols in the elf file), then copy it into your array at the beginning of the function using your preferred method.

Dan.

#21233 - sasq - Wed May 26, 2004 8:26 am

memcpy and memset should be in libgcc.a - which is normally linked unless you give a "nostdlibs" (or something like that) option to the linker. libgcc contains other stuff that it can be hard to live without like modulo functions and base-conversion functions...

#21240 - cosmic4z - Wed May 26, 2004 10:52 am

I've got libgcc on my HD ... but can't seem to link it in.

Infact I've got about 4 copies of it ....

E:\devkitadv\lib\gcc-lib\arm-agb-elf\3.0.2\libgcc.a
E:\devkitadv\lib\gcc-lib\arm-agb-elf\3.0.2\interwork\libgcc.a
E:\devkitadv\lib\gcc-lib\arm-agb-elf\3.0.2\thumb\libgcc.a
E:\devkitadv\lib\gcc-lib\arm-agb-elf\3.0.2\thumb\interwork\libgcc.a

Which one should I use !?

My gcc compiler flags and linker flags are:

CFLAGS = -ggdb -O -I$(AGBDIR)/include -I $(INCDIR) -mthumb-interwork -mthumb

LDFLAGS += -Map $(MAPFILE) -Ttext 0x08000000 -Tbss 0x03000000 -L$(AGBDIR)/lib/ -lagbsyscall -lisagbprn

If anyone can help ... that'd be great ... thanks :-)
_________________
Qwak - www.qwak.co.uk | Forum - www.qwak.co.uk/forum/

#21242 - bats - Wed May 26, 2004 11:17 am

Not sure if you already know this but your -llibname parameters must come after your object files.
For example,
Code:
gcc -o game.elf main.o -lgraphics


if main references symbols in the graphics library.

and you shouldn't have to tell gcc which ones library to use, it should figure it out automatically (for example, if you use -mthumb -mthumb-interwork, it will look in ...\thumb\interwork). I use devkitARM, and I've found that I don't even have to use -L$(libpath).

Ben

Edit:
I should have read these posts better.
From what I can tell memcpy/memset are in your libc.a libraries (try objdump -t libc.a | grep memcpy). These should be linked in automagically. If you are getting undefined reference errors during your link stage, I'd guess that it's either missing from your libc.a file (which I doubt because it's included in mine) or that you're not linking in libc (which should be automatic unless you pass -nostdlib).

#21285 - wintermute - Wed May 26, 2004 5:50 pm

cosmic4z wrote:
I've got libgcc on my HD ... but can't seem to link it in.

CFLAGS = -ggdb -O -I$(AGBDIR)/include -I $(INCDIR) -mthumb-interwork -mthumb

LDFLAGS += -Map $(MAPFILE) -Ttext 0x08000000 -Tbss 0x03000000 -L$(AGBDIR)/lib/ -lagbsyscall -lisagbprn

If anyone can help ... that'd be great ... thanks :-)



to start with I highly recommend using some sort of linkscript rather than attempting to set section addresses directly and don't use LD to link especially when using standard libraries.

something like

LD := arm-agb-elf-gcc

LDFLAGS := -mthumb -mthumb-interwork -Wl,-Map,$(MAPFILE),-Ttext,0x08000000,-Tbss,0x03000000

may do what you need.


I'd recommend switching over to DevkitARM though (obviously) </shameless plug> :P


LD := arm-elf-gcc
LDFLAGS := -mthumb -mthumb-interwork -Wl,-Map,$(MAPFILE) -specs=gba.specs