Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Using ZeroLink

ZeroLink speeds application development time by eliminating the link process from development builds. Instead, Xcode generates an application stub that contains the full paths to the object files that make up the application. At runtime, each object (.o) file is linked as it’s needed. This works only when running your application within Xcode. You cannot deploy applications using ZeroLink.

To turn ZeroLink on or off, use the ZeroLink (ZERO_LINK) build setting. ZeroLink is enabled by default in the Development build style. If you build with this build style, you automatically get ZeroLink functionality. See “Build Styles” for more information on using build styles. ZeroLink works only for native targets.

The following sections explain how you can customize ZeroLink to further reduce application launch times and identify issues you must keep in mind when using ZeroLink.

In this section:

Customizing ZeroLink
Caveats When Using ZeroLink


Customizing ZeroLink

ZeroLink postpones the linking of object files until the last moment possible. However, there are some symbols that, by default, are always resolved (that is, the corresponding object files are linked against the application and the code is executed). These symbols are static initializers in C++ and +load methods and categories in Objective-C. You can tell ZeroLink not to search the object files of your application for these symbols to reduce the application’s launch time.

There are situations that require the initialization of objects before a program’s main function is called. For example, a class may declare global variables that can be accessed by other code before the class has a chance to initialize them. In Objective-C, the +initialize method may be executed too late (see “Initializing a Class Object” in The Objective-C 2.0 Programming Language. The purpose of static initializers in C++ and +load methods in Objective-C is to provide developers with a mechanism to initialize variables at the earliest possible point during a program’s launch process. In Objective-C–based applications, categories are also loaded before main is called.

When you build an application, the static linker adds the standard entry-point function to the main executable file. This function sets up the runtime environment state for the kernel and the application before calling main, which involves calling static initializers for C++ code and loading categories and invoking +load methods for Objective-C code.

When using ZeroLink, you can further reduce the launch time of the application by postponing the execution of static initializers and +load methods, and the loading of categories. But you must be certain that code in your application doesn’t rely on static initializers or +load methods being called before main or on categories being loaded before main is called. Otherwise, your application may crash or behave unexpectedly.

There are three linker options you can use to customize ZeroLink in your project. To use these options, add them to the Other Linker Flags (OTHER_LDFLAGS) build setting:

When building an application that uses static libraries (.a files), each static library is linked to produce a bundle. At runtime, each bundle is loaded on demand. If your application starts slowly while using ZeroLink and has a large number (100 or more) of object files, you can try adding an intermediate static library target, containing the relatively stable parts of your source code. This gives you the best of both worlds: static (build time) linking for stable code and dynamic (runtime) linking for code that changes frequently.

If you want to view information about the loading and linking of object files as your application runs, set the ZERO_LINK_VERBOSE environment variable to any value. The information appears in run log of the application or stderr.

Caveats When Using ZeroLink

These are some things you should keep in mind when using ZeroLink:



< Previous PageNext Page > Hide TOC


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.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice