Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Universal Binary Programming Guidelines will assist experienced developers to build and modify their Mac OS X applications to run as universal binaries. Universal binaries run natively on Macintosh computers using PowerPC or Intel microprocessors and deliver optimal performance for both architectures in a single package.
This document is designed to help developers determine exactly how much work needs to be done and provides useful tips for general as well as specific code modification scenarios. It describes the prerequisites for building code as a universal binary and shows how to do so using Xcode 2.2. It also discusses the differences between the Intel and PowerPC architectures that can affect code behavior and provides guidelines for ensuring that universal binary code builds correctly.
This version of Universal Binary Programming Guidelines represents a significant update since its introduction at the Apple Worldwide Developers Conference in June, 2005. It brings together all the information that developers need to make the transition to Intel-based Macintosh computers. This version includes pointers to newly revised tools documentation—Building Universal Binaries, GCC Porting Guide, SDK Compatibility Guide, and more—as well as improved guidelines and tips. Anyone who has an older version of Universal Binary Programming Guidelines will want to replace it with this version.
Who Should Read This Document?
Any developer who currently has an application that runs in Mac OS X will want to read this document to learn how to modify their code so that it runs natively on all current Apple hardware. Developers who have not yet written an application for the Macintosh, but are planning to do so, will want to follow the guidelines in the document to ensure that their code can run as a universal binary.
Organization of This Document
This document is organized into the following chapters:
Building a Universal Binary shows how to use Xcode 2.2 to build native and universal binaries, describes build options, and provides troubleshooting information for code that doesn’t run properly on an Intel-based Macintosh computer.
Architectural Differences outlines the major differences between the x86 and PowerPC architectures. Understanding the differences will help you to write portable code.
Swapping Bytes describes byte-ordering differences in detail, provides a list of byte-swapping routines, and discusses strategies for a number of scenarios that require you to swap bytes. This is a must-read chapter for all Mac OS X developers. It will help you understand how to avoid byte-ordering issues when transferring data and data files between architectures.
Guidelines for Specific Scenarios contains tips for a variety of situations that are not common to most applications.
Preparing Vector-Based Code discusses the options available for those developers who have high-performance computing needs.
This document contains the following appendixes:
Rosetta describes the translation process that allows PowerPC binaries to run on an Intel-based Macintosh computer.
Architecture-Independent Vector-Based Code uses matrix multiplication as an example to show how to write vector code with a minimum amount of architecture-specific coding.
32-Bit Application Binary Interface provides information on where to find details.
64-Bit Application Binary Interface provides information on where to find details.
The document assumes the following:
Your application runs in Mac OS X.
Your application can use any of the Mac OS X development environments: Carbon, Cocoa, Java, or BSD UNIX.
If your application runs in the UNIX operating system but not specifically in Mac OS X, you should first read Porting UNIX/Linux Applications to OS X.
If your application runs only in the Windows operating system, you should first read Porting to Mac OS X from Windows Win32 API.
If you are new to Mac OS X, you should take a look at Mac Technology Overview.
You know how to use Xcode.
Currently Xcode is the only GUI tool available that compiles code to run universally.
If you are unfamiliar with Xcode, you might want to take a look at Xcode Workspace Guide.
If you have been using CodeWarrior, you should read Porting CodeWarrior Projects to Xcode.
The term x86 is a generic term used in some parts of this book to refer to the class of microprocessors manufactured by Intel. This book uses the term x86 as a synonym for IA-32 (Intel Architecture 32-bit).