< Previous PageNext Page > Hide TOC

Defining Executable Environments

An executable environment defines how a product is executed when you run it from Xcode. The executable environment tells Xcode which program to launch when you run the product, as well as how to launch it. Xcode automatically creates an executable environment for each target that produces a product that can run on its own. You can also create your own executable environments for testing products such as plug-ins or frameworks for which you don’t have the corresponding Xcode projects. You can set up multiple custom executable environments for testing your program under varying sets of circumstances, or use a custom executable environment to debug a program you do not have the source to.

This chapter describes how to view the executables in your project and how to configure an executable environment.

In this section:

Executable Environment Overview
Setting the Active Executable
Creating Custom Executable Environments
Configuring Executable Environments


Executable Environment Overview

The executable environment defines:

Generally, you do not have to create executable environments; in most cases, Xcode does this for you. If you are creating a target that produces a product that can be run by itself—such as an application—Xcode automatically knows to use the application when you run the product.

However, if you have a product that can’t be run by itself—such as a plug-in for a third party application—you need to create your own executable environment. This custom executable environment specifies the program to launch when you run the product, such as the application that uses your plug-in.

Even if your target creates a product that can run on its own, you may also want to customize the executable environment associated with it, in order to pass arguments to the executable or test it with environment variables.

Executable environments defined for a project are placed in the Executables group in the Groups & Files list in the project window. Executable environments that you define are stored in your user file for the project—that is, in the .pbxuser file in the project package (see “The Project Directory” for details). As a result, each developer working on a project defines her or his own executable environments. When you run a product in Xcode, Xcode launches the program specified by the active executable, as described in the “Setting the Active Executable.”

Setting the Active Executable

The active executable is the executable environment that Xcode uses when you run a product. Xcode tries to keep the active target and the active executable in sync; if you set the active target to a target that builds an executable, Xcode makes that target’s executable the active executable. Otherwise, the active executable is unchanged. If you use a custom executable environment to test your product, you have to make sure that the active executable is correct for the target you want to run.

The active executable is indicated by the blue (selected) button in the detail view. To change the active executable, do either of the following:

Creating Custom Executable Environments

Many targets create a product that can be run by itself, such as an application or command-line tool. When you create such a target, Xcode adds an entry to the Executables group that points to the target’s product, and it knows to use that executable environment when you run the target.

Sometimes, though, you have a product that can’t run by itself: for example, a plug-in or a framework. Even if your product can run by itself, you may want to run the product under different conditions to test it. For example, you may want to test a command-line tool by passing it specific command-line arguments. Or you may have an application that performs differently depending on the value of an environment variable.

In these cases, you need to create a custom executable environment. You may have several executable environments for exercising the product of a single target. For example, you could have several applications that test different aspects of a framework. Or you could have several lists of command-line arguments and environment variables that test different aspects of a command-line tool.

You can also use custom executable environments to debug programs in Xcode, even if you do not have an Xcode project for the program. For example, you may have a program that you did not build in Xcode, or a program that was built by another person, to which you do not have the source. To run this program in the debugger, you simply create an empty project and add one or more custom executable environments that are configured to launch your program.

To create a custom executable environment, choose Project > New Custom Executable.

Xcode displays a dialog in which you can specify characteristics for your executable environment:

When you click Finish, Xcode adds the new executable environment to the chosen project. You can change the program that Xcode launches when using this executable environment—along with other executable settings—in the Executable Info window, as described in “Configuring Executable Environments.”

Configuring Executable Environments

Executable environments give you control over how your product is run when you launch it from Xcode. To configure an executable environment, select it in the Groups & Files list or in the detail view, and open the Executable Info window. The following sections describe the settings you can configure in the Info window.

Executable-Environment General Settings

The General pane of the Executable Info window (Figure 8-1) lets you configure essential aspects of an executable environment.


Figure 8-1  General pane of the Executable Info window

Executable-environment editor: General pane

These are the executable-environment aspects the General pane allows you to configure:

Executable-environment paths: Executable-environment settings such as path and working directory refer to specific locations in your file system. If you change the project’s build directory, you may break the project’s executable environments. To create more flexible executable environments, you can use build settings to specify executable-environment settings in relation to a project’s base locations. For example, if you create an executable environment and specify the executable path as $(CONFIGURATION_BUILD_DIR)/Sketch.app, you can later change the location of the project’s build directory without breaking this executable environment. See Xcode Build Setting Reference for more on build settings that identify a build and product locations.

Executable-Environment Arguments

If your product takes command-line arguments, you can define those arguments in an executable environment. Xcode passes those arguments to the product’s binary when you run the product.

To test your product under different conditions, you can create multiple executable environments, each with different arguments. Changing your test environment becomes as simple as changing the active executable.

You specify arguments to pass to the binary, as well as environment variables that the executable environment sets before launching the binary, in the Arguments pane of the Executable Info window (Figure 8-2).


Figure 8-2  Arguments pane of the Executable Info window

Executable-environment editor: Arguments pane

These are the executable-environment aspects the Arguments pane allows you to configure:

To learn more about the directories used in the build process, see “Build Locations.” For more information on these build settings, see Xcode Build Setting Reference.

Executable-Environment Debugging Information

Executable environments specify a set of debugging-specific items that specify which debugger to use, as well as how Xcode communicates with the debugger. (You debug a product when you start it with breakpoints activated.) You configure these items in the Debugging pane of the Executable Info window, shown in Figure 8-3.


Figure 8-3  Debugging pane of the Executable Info window

Executable-environment editor: Debugging pane

These are the executable-environment aspects the Arguments pane allows you to configure:

If you have the source code to the application, you can make that source code available to the debugger so you can see the source for variables and set breakpoints. See “Executable-Environment Debugging Information” to learn how to add source-code directories to an executable debugging environment. This operation makes your source code available to the debugger, but does not give you any of the source code navigation features of Xcode or make the source code available to you to set breakpoints before the debugging sessions starts. For this type of access, you can add the source code directly to your project, as described in “Managing Files and Folders in a Project.”



< Previous PageNext Page > Hide TOC


© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-01-06)


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.