views:

50

answers:

2

I'm making a game engine for mobile devices. I want to compile my code, link it against a few static libraries and then combine my compiled code with those static libraries to form a new static library. However, my Google Fu is abandoning me.

Suppose I have static libraries a.a, b.a and c.a and my code. I want to compile all that into awesome.a.

How can I do that?

I'm using CodeSourcery's arm-none-linux-gnueabi-ar by the way.

Thanks in advance.

+2  A: 

Assuming that a.a, b.a, and c.a are in the CWD, something like:

mkdir a-objs && ( cd a-objs && ar -x ../a.a )
mkdir b-objs && ( cd b-objs && ar -x ../b.a )
mkdir c-objs && ( cd c-objs && ar -x ../c.a )
rm -f awesome.a && ar -r awesome.a a-objs/* b-objs/* c-objs/* && ranlib awesome.a

should work.

Aidan Cully
Ah, okay, but can I then also combine that with my compiled code (my .o's)?
knight666
knight666
A: 

If you want to put code into a static library, you do NOT link it. A static library isn't linked at all though. It's just a collection of object files put into a single file for the sake of convenience.

You create object files, and put them into the library. If you want to add your object files into an existing library instead of creating a new one, that's fairly trivial to (though if the existing library is well enough known for anybody to have expectations about what it does or doesn't contain, I'd say it's probably a bad idea to add new things people won't know to expect).

Jerry Coffin