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 > Linking object files

#7632 - regularkid - Sat Jun 21, 2003 8:22 pm

Is is possible to compile a bunch of object files (the result of compiling c files) into one single object file? This way I can compile all my engine code into a single object file separately and then link it with the game code object files. This will give me a way to keep engine code and game code separate and be able to use the engine in multiple game projects.
I'm basically looking for something like this to put into my makefile (I can't seem to get it working):

Code:

Engine.o : Code1.o Code2.o Code3.o
    gcc Engine.o -o Code1.o Code2.o Code3.o


Thanks.
_________________
- RegularKid

#7633 - bomberman - Sat Jun 21, 2003 11:14 pm

Basically, you want to do a library...
I just did that for my recent released Tetris and hopefully numerous future projects :O)

My makefile is something like that to create the library
PROGNAME=MyLib
LIB_OFILES += Code1.o Code2.o Code3.o

all : $(PROGNAME).a

$(PROGNAME).a: $(LIB_OFILES)
$(GCCARM)/arm-thumb-elf/bin/ar.exe rcs lib/$@ $(LIB_OFILES)

#7636 - regularkid - Sun Jun 22, 2003 2:28 am

Hmm. I have the library compiling fine, but now how do I go about linking it with my game code object files into a single elf? Thanks.
_________________
- RegularKid

#7639 - tepples - Sun Jun 22, 2003 4:39 am

regularkid wrote:
Hmm. I have the library compiling fine, but now how do I go about linking it with my game code object files into a single elf? Thanks.

Link it like any object file:
gcc -mthumb -mthumb-interwork foo.o bar.o baz.o libengine.a -o game.elf
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#7641 - regularkid - Sun Jun 22, 2003 4:53 am

I finally got it working. Thanks for the help, guys!
_________________
- RegularKid