Creating Universal Binaries

Building UB QT

Firstly build a native version of QT3 on your machine. This document will assume that that you are building on an Intel machine and cross compiling for PPC. Once you have built QT for Intel rename /Developer/qt to /Developer/qt-intel and create an entirely fresh new QT3 tree.

Next cd into /Developer/qt/mkspecs/macx-g++ and edit qmake.conf. Change QMAKE_CFLAGS and QMAKE_LFLAGS to the following:

QMAKE_CFLAGS = -pipe -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk
QMAKE_LFLAGS = -headerpad_max_install_names -arch ppc -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk
    

If you are building for Intel on a PPC machine swap i386 for ppc in the above 2 lines. Please note that you will need the MacOSX 10.4 SDK installed. This can be downloaded from Apple

Now build the new PPC version of QT3 with the usual ./configure and make procedure.

Creating libqt.3.dylib

Next a UB version of libqt.3.dylib needs to be created. Copy the version of libqt.3.dylib from /Developer/qt-intel to a temporary location and rename it to libqt.3.dylib-intel. Do the same for the PPC version of the library.

Strip each library of its symbol table using the following:

strip -x libqt.3.dylib-intel
strip -x libqt.3.dylib-ppc
    

Next use the ''lipo'' utility to stitch the 2 libraries together into a single Universal Binary version:

lipo -create libqt.3.dylib-intel libqt.3.dylib-ppc -output libqt.3.dylib
    

Ensure that the QT library has its path changed to include a relative id:

install_name_tool -id @executable_path/libqt.3.dylib libqt.3.dylib
    

Now cp the new UB libqt.3.dylib back into /Developer/qt-intel/lib and /Developer/qt-ppc/lib. Finally cp libqt.3.dylib to trunk in preparation to create the installer image.

Building Your Software

Now perform a clean rebuild of the software code. To do this use make clean as normal but also touch your .pro to force the Makefile to be regenerated.

This will build the PPC version. Once built copy the executable to a temporary location and rename it to myapp-ppc.

Now move /Developer/qt to qt-ppc and put qt-intel back in place and perform a clean rebuild of your application (touching .pro int the process). Rename the executable to myapp-intel.

Preparing the Executable

Firstly strip the symbol tables from the 2 executables using the "strip" utility:

strip myapp-intel
strip myapp-ppc
    

Next use "lipo" to stitch the 2 executables together into a single Universal Binary:

lipo -create myapp-intel myapp-ppc -output myapp
    

Once this has finished run the following to check the new executable:

file myapp
    

This should output something like the following:

myapp: Mach-O universal binary with 2 architectures
myapp (for architecture i386):       Mach-O executable i386
myapp (for architecture ppc):        Mach-O executable ppc
    

And finally copy the executable back into your myapp.app tree under Contents/MacOS.

Links

http://developer.apple.com/technotes/tn2005/tn2137.html
http://www.trolltech.com/developer/knowledgebase/766
http://lists.trolltech.com/qt-interest/2006-06/thread00043-0.html
Locations of visitors to this page