Cutting out the fat

Mac OS X has the unfortunate problem of trying to support two chip architectures without causing headaches for users. The solution to this is to compile applications as "fat binaries", meaning, code for more than one achitecture is part of the binary package.

I'm not really a fan of this solution, since it wastes harddrive space for everyone. The only upside to it is that allows users who know nothing about what chip is in their computer to remain ignorant. Also, it typically doesn't cause problems for anyone.

Unless you are a developer.

If you happen to straddle the fence between open source and Apple provided libraries and tools, you could run into problems.

For instance, software compiled and installed using Fink is built only for the architecture that you are running on. There's no reason to waste space by building PPC code if you are using an x86 chip.

This can cause problems if you are trying to build a Python module that links against Fink installed libraries. Most Python distros for OS X are fat binaries. If you get a Python module that builds from source using distutils, it will try to build the code to match your architecture. In my case this means it creates a fat binary.

However, if you are missing the fat versions of libraries that the module references (say things from Fink), then you get compile errors when it can't find the library code for the other architecture.

I've run into this problem more than once and until recently haven't been able to find a way to tell distutils to only build code for one architecture. So, I'm documenting the solution here (mostly for myself and perhaps for some other poor soul who is able to find this using Google).

The solution comes by modifying the Makefile that is part of the Python distribution:



Now, edit the Makefile to remove instances of "-arch x" for the architectures that you are not using. Here is an example of the edits I needed to make:



And there you have it. Module builds using distutils will automatically pick up the change and stop building for unused architectures.

Thanks to Wongo, linked below, for making the blog post that I found and allowed me to solve this problem.

Wongo’s Scraps of Code » Does my Mac really love me?.