This evening I was experimenting with universal binaries in Qt, as documented in the Qt tutorial. At the risk of duplicating some information, I’ll explain the slightly different route that I took for building the universal binaries.
Before you get started, if you’ve got a PowerPC processor, you’ll need to make sure the 10.4 SDK is installed. It’s available with the Developer installers. You’ll also need to install a version of Qt that supports universal binaries.*
The primary limitation of using qmake to build universal binaries is that it will only run on Mac OS 10.3.9 or later, since GCC 4.0 is required to build. Binaries built with GCC 3.3 will run on previous versions of Mac OS X, but you cannot use GCC 3.3 to build universal binaries.
Rather than release separate bundles for 10.3 and 10.4, you can build a PowerPC binary for 10.3 and an Intel binary for 10.4, then use the lipo tool to stitch them together. The Qt documentation recommends using the gcc_select command to switch compiler versions, but this is very cumbersome for release scripts, since it requires that you enter a root password. Instead, you can force qmake to use a specific version of GCC.
To build a PowerPC binary that’s compatible with Mac OS 10.3, use this configuration, then save a copy of the binary.
QMAKE_CC=/usr/bin/gcc-3.3
QMAKE_CXX=/usr/bin/g++-3.3
QMAKE_LINK=/usr/bin/g++-3.3
CONFIG+=ppc
To build the Intel binary, use this configuration, then and save a copy of the binary.
QMAKE_CC=/usr/bin/gcc-4.0
QMAKE_CXX=/usr/bin/g++-4.0
QMAKE_LINK=/usr/bin/g++-4.0
CONFIG+=x86
From there, creating the universal binary is a simple matter.
lipo path/to/ppc/binary path/to/x86/binary -create -output path/to/universal/binary
If you like, you can use file to verify that the universal binary was created correctly.
Then, drop your universal binary into your bundle, and you’re good to go. Of course, you’ll want to automate this process so that you don’t have to build the universal binary hand every time, but I’ll leave that as an exercise for you, the reader.
Additional Resources:
Nice entry. Do you have any hints on building the 3.3/ppc and 4.0/intel Qt Frameworks and lipo-ing them together?
Comment by Ian Scott [Visitor] — May 24, 2006 @ 12:49 pm
First of all, let me mention that Apple has a very helpful resource on the Anatomy of Framework Bundles that you might want to check out.
Although I haven’t specifically done this yet, here would be one way to do it:
Build and install Qt in two separate locations for GCC 3.3 and 4.0, using “sudo gcc_select 3.3″ and “configure -prefix /usr/local/Trolltech/Qt-4.1.2/gcc-3.3″ for GCC 3.3 and the equivalent for GCC 4.0. (You can probably do this without using gcc_select, but I haven’t taken the time to figure out how.)
Use “cp -R” to make a copy of one of the frameworks (say /gcc-4.0/libs/QtCore.framework).
Run “lipo /some/path/gcc-3.3/libs/QtCore.framework/Versions/4.0/QtCore
/some/path/gcc-4.0/libs/QtCore.framework/Versions/4.0/QtCore -create -output /some/path/universal/QtCore.framework/Versions/4.0/QtCore”.
From there follow the steps described in Trolltech’s article on Deploying an Application on Qt/Mac.
As always, I suggest you integrate this into your build script!
Let me know how this works, as I haven’t actually given this a try.
Comment by Matthias Miller [Member] — May 24, 2006 @ 3:25 pm