Saturday, February 23, 2008

Universal Binaries

Since most Mac programs need to run on x86 and ppc architectures (which are rather different) you will find that most mac binaries are distributed as something called a "Universal Binary". Example "file" output:

fileoffsets-macbook:MacOS fo$ file Adium 
Adium: Mach-O universal binary with 2 architectures
Adium (for architecture ppc): Mach-O executable ppc
Adium (for architecture i386): Mach-O executable i386


Essentially a Universal Binary is just a bundle which consists of both the x86 and ppc compiled versions of the binary in question. This is good for Mac owners, because it means that for the most part you don't have to know, or even care which CPU your Mac has as OS X will choose the correct binary to run when you execute the application. It's totally transparent to the user.

What this does mean however is that for every Universal Binary, you will be downloading two separate versions of the binaries and bundled libraries (more on this later).

This is the reason that on some websites, where certain programs are available for download for both Windows and Mac OS X, the OS X download may be as much as double the size of the Windows ones.

To extract a single version of the binary, you can use a command line tool called 'ditto', e.g:

ditto --arch i386 <source filename> <dest filename>

This will copy the x86 version of the binary out of the Universal Binary, to the <dest filename>.

No comments: