Building a universal library in Mac OS X

If you need to use a library in a universal binary you'll need to use a universal library too.

Let's use FMOD as an example; libfmod.a is the PPC compiled version, libfmodx86.a is the intel version.

For combining both into a universal library:


lipo -create libfmodx86.a libfmod.a -output libfmod-universal.a
ranlib libfmod-universal.a

In the case of FMOD they provide you the with precompiled static libraries (the .a files). But if you build libraries from source code, there's a magic compiler option called -arch which will help you in this. Unfortunately I don't have an example handy right now. I'll put it whenever I find it again, but it roughly goes on the lines of -arch i386 -arch ppc :-)

I'm not sure that naming a library with something as *-universal.a is a good idea, specially if you have code which uses -Llibraryname for linking libraries -- I guess you might need to change that parameter. I am explicitly adding the libraries to the project in XCode so it's working fine for me.

Suggestions and better practices are welcome!