soledad penadés
repeat 4[fd 100 rt 90]

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!

// 3 responses to Building a universal library in Mac OS X

Fabien
Fabien
20080505

Hi !

Just a little message to complete this post about building universal library on Mac OS X. Because incompatibilities between Tiger & Leopard, if you build your library on Mac OS X 10.5, you must set this flags :
CFLAGS=”-arch ppc -arch i386 -mmacosx-version-min=10.4 -universal -isysroot /SDKs/MacOSX10.4u.sdk”
LDFLAGS=”-arch ppc -arch i386 -mmacosx-version-min=10.4 -Wl,-isyslibroot,/SDKs/MacOSX10.4u.sdk”

Congratulation for this nice website !

Fabien.

sole
sole
20080505

Good point!

I still haven't tested building a library for Tiger, using Leopard. Although it's slightly different if one uses Xcode. But anyway they are good hints.

Thanks!

Lua universal binary - soledad penadés
Lua universal binary - soledad penadés
20080519

[...] this post, this one and this comment and you get a Lua universal build for your mac in Leopard - which works for Tiger too! Assuming you [...]

Feel free to leave a reply

Comments are moderated: Rude and offtopic ones are out!