Universal Binaries in Macports

Tim found a secret in Macports that solves my problem building PIL for Python2.5 on Snow Leopard (SL).

It turns out that by default (at least on SL) Macports only builds a x86_64 binaries. Running the file command shows it’s only one architecture, something like:

[berto@bolt][524]$ file /opt/local/lib/libpcrecpp.dylib
/opt/local/lib/libpcrecpp.dylib: Mach-O 64-bit dynamically linked shared library x86_64

SL’s Python2.5 isn’t even built for x86_64, which is the reason PIL blows up in Python2.5:

[berto@bolt][523]$ file /usr/bin/python2.5
/usr/bin/python2.5: Mach-O universal binary with 2 architectures
/usr/bin/python2.5 (for architecture i386):	Mach-O executable i386
/usr/bin/python2.5 (for architecture ppc7400):	Mach-O executable ppc

The solution is to tell Macports to build universal binaries. This can be done by adding +universal to the command line, for example:

sudo port install jpeg +universal

A more general solution is to add this “variant” to the Macports config. Simply add +universal to the file /opt/local/etc/macports/variants.conf. The file is read-only, even for root, so make sure to force-write the file (:wq! in vi).

And if you want to rebuild everything universal, sledgehammer approach:

sudo port upgrade --force installed

More info from Tim:

Note that the architectures it picks might not be what you want. On Leopard Intel it appears to do i386 x86_64. If you want ppc, set ‘universal_archs ppc i386 ppc64 x86_64’ (note NO EQUALS).

in /opt/local/etc/macports/macports.conf

Rebuilding all is the command you wanted, or for just the specific ones
needed, ‘sudo port upgrade –enforce-variants curl’ should do it to add
+universal (it won’t rebuild when you change universal_archs though).

Once Macports is universal, rebuilding and installing PIL works like a charm!


6 thoughts on “Universal Binaries in Macports”

  1. This was very handy for preparing my 10.6 install for building wine-devel with macports. Thanks!

  2. Good article on this, but it may be easier for some users to simply tell the setup.py script to build only for a specified architecture. For instance, I did an ‘in place’ build on my intel Mac by doing the following (caution: this assumes you have already installed the dependent libraries for jpeg, png, etc…):

    $MacHD:Imaging-1.1.7 asw$ ARCHFLAGS=”-arch i386″ python setup.py build_ext -i

    This worked like a charm on 10.5.8 with Python 2.6, libjpeg 6a, libpng 1.4.1, and Freetype 2.3.9 (all installed in /usr/local/lib). Clearly this won’t work if your libxml2.2.dylib is of the wrong architecture, but since that’s never supposed to happen with a correct Macport install it really shouldn’t matter.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s