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.

DS development > how to create an archive and get it working with devkitARM..

#136221 - troymclure - Mon Jul 30, 2007 8:25 am

i am trying to create a static library for NDS with devkitARM with no success. For instance let's suppose i want an archive with the C function "int increment (int)"
then i create the file archive.c like this:

int increment (int a) {

return a + 1;
}

so i compile it like this: /home/troymclure/devkitPRO/devkitARM/bin/arm-eabi-gcc
-c archive.c -o archive.o

then i create the archive like this: /home/troymclure/devkitPRO/devkitARM/bin/arm-eabi-ar -r archive.a archive.o

and i got the file archive.a and no errors or warning mesages are issued by arm-eabi-ar and everything looks ok.

then the problem is to tell to the linker to link my library. under linux i just do something like this: gcc my_main_code.o archive.a -o my_program.out
with devkitARM i have to use a makefile and currently i don't uderstand all the sintax of the makefiles under the libnds examples. i just use the makefile of the example ../Graphics/2D/16bit_color_bmp and i just edit it at my purpose, u know, as a template. could please anyone let me know how to edit this template to make the linker link my archive?

#136226 - Ant6n - Mon Jul 30, 2007 9:42 am

where it says,
Code:
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS   := -lnds9

you could try to add your library there "-archive". lnds9 is actually a file called lnds9.a that's somewhere in devkitarm's directories. so if you add yours there, it should work. You have to put your archive somewhere the linker can find it though (i.e. same directory as makefile or path or something)

#136233 - jackman - Mon Jul 30, 2007 11:30 am

Ant6n wrote:
where it says,
Code:
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS   := -lnds9

you could try to add your library there "-archive". lnds9 is actually a file called lnds9.a that's somewhere in devkitarm's directories. so if you add yours there, it should work. You have to put your archive somewhere the linker can find it though (i.e. same directory as makefile or path or something)

thats not right at all, the file ist called libnds9.a, the linker will replace -lnds9 with -l libnds9.a, so to include the archive.a, use this command line: -l archive.a
complete:
Code:
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS   := -lnds9 -l archive.a

you have to copy the archive.a into the /lib directory (not /arm-eabi/lib) of devKitARM
_________________
Equipment:
Nintendo DS, GBAMP v2, SuperCard SD, SuperKey, Acekard 2i


Last edited by jackman on Mon Jul 30, 2007 11:32 am; edited 1 time in total

#136234 - simonjhall - Mon Jul 30, 2007 11:32 am

Don't forget to put the archive in a place searched by the linker (eg the libnds libs directory) or add an extra search directory with -L your_directory_here
_________________
Big thanks to everyone who donated for Quake2

#136274 - troymclure - Mon Jul 30, 2007 9:52 pm

ok ... thanks for the help, now i can get the linker to find my library. but the problem is that the linker give me the error: "untefined reference to...". i guess i am doing something wrong on creating the archive, under linux i just compile c code into object file. and then i create the archive like this: ar -r archive.a object.o ... do i have to do anything different here ?