< Previous PageNext Page > Hide TOC

Cross-Development and Universal Binaries

Beginning with Xcode 2.1, you can take advantage of cross-development to create universal binaries—executable files containing object code for both Intel-based and PowerPC-based Macintosh computers. For more information on creating universal binaries, see Universal Binary Programming Guidelines, Second Edition.

To compile code for an Intel-based Macintosh, you must compile using GCC 4.0 and target the Mac OS X 10.4 (Universal) SDK. If you can require Mac OS X v10.4 or later, you can use the same cross-development settings to build for either architecture. However, you may want to support Mac OS X v10.3 and later for PowerPC-based Macintosh computers.

If you're creating a universal binary version of a kernel extension (a generic KEXT or an I/O Kit driver), be aware that some I/O Kit classes in an Intel-based Macintosh running Mac OS X v10.4 are intentionally not binary compatible with the same classes in a PowerPC-based Macintosh running Mac OS X v10.4. If your KEXT needs to run in both versions, be sure to target the Mac OS X 10.4.0 (or earlier) SDK for the PowerPC build and the Mac OS X 10.4 (Universal) SDK for the Intel-based build. For more details on building universal I/O Kit device drivers, see Technical Note TN2163.

Note: The Mac OS X 10.4.0 SDK—which is distinct from the Mac OS X 10.4 (Universal) SDK—no longer ships with Xcode Tools. You can download it from the Downloads section of the ADC Member Site.

Xcode provides per-architecture variants for a number of build settings to allow you to specify different cross-development settings for Intel and PowerPC-based builds. These variants take the form BUILD_SETTING_($arch) where BUILD_SETTING is the usual name of the build setting and ($arch) is a suffix denoting the architecture for which the build setting applies. The i386 suffix indicates the architecture for Intel-based Macintosh computers, and the ppc suffix indicates the PowerPC architecture. For example, to specify that Xcode use GCC 4.0 when building for Intel, set the GCC_VERSION_i386 build setting to 4.0. The build settings that have per-architecture variants related to cross-development are listed in Table 3-1. For more on build settings in Xcode, see Xcode 2.2 User Guide.

Table 3-1  Xcode cross-development settings with per-architecture variants

Build setting

Description

SDKROOT

The SDK to develop for.

MACOSX_DEPLOYMENT_TARGET

The deployment target, which specifies the earliest version of Mac OS X on which your software can run.

GCC_VERSION

The version of GCC to use when building.

Important: Per-architecture build settings are supported only in Xcode 2.2 and later.

Note: By default, the Build pane of the target and project inspectors contains only the general version of each build setting, without any architecture-specific suffix. You must manually create entries in the build settings table for any per-architecture variants you wish to add. To learn more about adding build settings in Xcode, see Xcode 2.2 User Guide.

Using these per-architecture settings, you can create a single target that creates a universal binary and builds for Mac OS X v10.4 on Intel-based Macintosh computers while supporting Mac OS X v10.3 and later for PowerPC. The basic steps for configuring your project or target are the same as those described in “Configuring Your Project for Cross Development”:

  1. Choose a target SDK.

    To target Mac OS X v10.4 for both Intel- and PowerPC-based builds, choose the Mac OS X 10.4 (Universal) SDK from the Cross-Develop Using Target SDK menu.

    Note: You can specify different target SDKs for Intel and PowerPC builds. For example, when building for PowerPC, you may want to ensure that your code doesn't use features from versions of Mac OS X later than Mac OS X v10.3.9.

    To do so, add new entries for the SDKROOT_ppc and SDKROOT_i386 build settings to the table in the Build pane of the target or project inspector. Set SDKROOT_ppc to point to the Mac OS X 10.3.9 SDK and set SDKROOT_i386 to point to the Mac OS X 10.4 Universal SDK. You can type the full path to each SDK or simply drag the SDK folder from the Finder to the Value column.

  2. Set the deployment target.

    To support versions of Mac OS X prior to Mac OS X v10.4 for PowerPC, you can specify separate deployment OS versions for Intel and PowerPC-based builds. To do so, use the per-architecture variants of the MACOSX_DEPLOYMENT_TARGET build setting:

    1. In the target or project inspector, add entries for the MACOSX_DEPLOYMENT_TARGET_ppc and MACOSX_DEPLOYMENT_TARGET_i386 build settings.

    2. Set MACOSX_DEPLOYMENT_TARGET_i386 to 10.4.

    3. Set MACOSX_DEPLOYMENT_TARGET_ppc to the earliest system version that you want to support for PowerPC. For example, to support Mac OS X v10.3 and later, set MACOSX_DEPLOYMENT_TARGET_ppc to 10.3.

  3. Select the appropriate compiler.

    As mentioned, you must use GCC 4.0 to compile for Mac OS X v10.4 and for Intel-based Macintosh computers. However, code built with GCC 4.0 will not run on versions of Mac OS X earlier than 10.3.0. Furthermore, due to changes in the C++ ABI between the GCC 4.0 and GCC 3.3 compilers, C++ or Objective-C++ code built with GCC 4.0 does not run on versions of Mac OS X prior to Mac OS X v10.3.9.

    If you can require Mac OS X 10.3.9 or later (10.3.0 or later if you do not have C++ or Objective-C++ code), you can use the same version of GCC to build for both Intel- and PowerPC-based Macintosh computers. Otherwise, you must use different versions of the GCC compiler to build for each platform. To do so, use the per-architecture variants of the GCC_VERSION build setting:

    1. In the Build pane of the target or project inspector, add entries to the build settings table for the GCC_VERSION_ppc and GCC_VERSION_i386 build settings.

    2. Set GCC_VERSION_ppc to 3.3.

    3. Set GCC_VERSION_i386 to 4.0.

    Note: Xcode also has per-architecture build setting variants for the LD and LDPLUSPLUS build settings; this lets you specify different linker versions for PowerPC and Intel builds.

Although it is easiest to build universal binaries from Xcode, you can also build them from the command line. For an example of how to build from the command-line targeting the same SDK for both Intel and PowerPC-based builds, see Compiling Your Code in Mac OS X in Porting UNIX/Linux Applications to Mac OS X.

If you need to target different SDKs for Intel and PowerPC-based builds—for example if you need to support versions of Mac OS X prior to Mac OS X v10.4 for PowerPC-based builds—you will need to compile for each architecture separately and then use the lipo tool to create a single executable file. To build a binary for Intel-based Macintosh computers, use the settings described in “Configuring a Makefile-Based Project” to specify the target SDK and the deployment target. For instructions on using lipo, see lipo(1).



< Previous PageNext Page > Hide TOC


© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-11-07)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.