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.

Beginners > What parameters to use with GCC

#34616 - donpeppoe - Sat Jan 22, 2005 4:23 pm

In different tutorials i've seen different ways to compile an binary with devkitadv

Code:

gcc -o main.elf main.c  -lm
objcopy -O binary main.elf main.gba


and

Code:

gcc -c -O3 -mthumb -mthumb-interwork main.c -w
gcc -mthumb -mthumb-interwork -o main.elf main.o -w
objcopy -O binary main.elf main.gba


the results of the binaries are not the same.

What is the correct way (which is compatible with GBA hardware)

any idea's? Thanks!

#34630 - tepples - Sat Jan 22, 2005 10:54 pm

Code:
gcc -o main.elf main.c  -lm

This compiles a single file to unoptimized ARM code and links it using the ARM version of the C library. ARM code will run more slowly on the GBA than optimized ARM code, which in turn will run more slowly than optimized Thumb code when run from ROM (the default) or EWRAM (the default for multiboot programs). The -lm is floating point stuff, which you usually don't want on a platform such as the GBA that has no floating point unit.

Code:
gcc -c -O3 -mthumb -mthumb-interwork main.c -w
gcc -mthumb -mthumb-interwork -o main.elf main.o -w

I'm not sure what the -w does, but the first line compiles a single file to optimized Thumb code (-c means just compile, don't link), and the second line links it with the Thumb version of the C library.

Code:
gcc -O3 -mthumb -mthumb-interwork -o main.elf main.c

This does the same as the first example, except using optimized (-O3) Thumb code (-mthumb -mthumb-interwork) and the Thumb version of the C library.

The "objcopy" part, which turns a .elf file (which runs in emulators and can hold debug information but cannot hold appended data nor run on hardware) into a .gba file (which runs in emulators and on hardware and can hold appended data but cannot hold debug information), is identical in all three cases.

Tip: DevKit Advance is old and deprecated. If you use devkitARM instead of DevKit Advance, then on the command line that calls the linker (the one containing -o main.elf), you must specify -specs=gba.specs (for a ROM) or -specs=gba_mb.specs (for a multiboot).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#34633 - sajiimori - Sun Jan 23, 2005 12:01 am

-w disables warnings, which I would not recommend for projects large enough to span multiple files. -Wall enables all warnings, which is generally preferable.

#34656 - donpeppoe - Sun Jan 23, 2005 1:39 pm

ok, i switched to ARM

i use

Quote:

arm-elf-gcc -mthumb-interwork -c main.c -o main.o
arm-elf-gcc -mthumb-interwork -c framework/functions.c -o functions.o
arm-elf-gcc -mthumb-interwork -specs=gba_mb.specs main.o functions.o -o game.elf
arm-elf-objcopy -O binary game.elf game.gba


and it all seems to work

Thanks for the help!