An Xcode 4 iOS Project with a Static Library and an Application

This tutorial covers creating an Xcode project for an iOS application that includes a static library in a form that debugging can enter the libraries source.

It assumes that you:

  • have already created your static library.
  • have your application project open.
  • have no other include paths added yet

Step 1 Add a Source Tree for the Library Source.

In the Xcode preferences, select the “Source Tree” tab.

Add a new setting, the setting name is the variable that you will use to reference the path to your static library in the combined project. Try to keep it short and descriptive.

The display name is the name you will use to select it from certain drop down lists.

The path is the full path to the directory containing your static library’s .xcodeproj.

For example

This step allows you to separate the location of your library from its reference in the application project.

Step 2 Add the Library Project as a Subproject of the Application.

Right click on the application project in the file browser pane of Xcode, and select “Add Files …”

The result should look like this

Where the Library project is nested inside the application project.

 

 

 

Step 3 Set the Location of the Library Project

This is the step that promotes the independence of the application project from the actual location of the library project. Select the library project in the file browser

 

 

 

 

And edit the location property in the right hand properties browser

Select the source tree display name you created in step 1.

With this step, you can now put your library in a different location by changing the source tree entry. (Or swap to a different version)

 

 

Step 4 Add the Library code to the Include path.

In the file browser, click on the application project.

Then select the project’s  target’s build settings

 

 

 

 

Scroll down to the “Search Paths” section:

 

 

 

 

Clicking on the “Header Search Paths” line will cause a reveal triangle to appear on the line

 

Click on the triangle, the place to add paths for the release and debug builds will be revealed. Click on the Debug line

Then click to the right of the + sign

In the revealed edit box, add the setting name you created in step 1 enclosed in $( and ) followed by the path to the libraries header files. ( in an xcode 4 project with unit tests they are usually in a subdirectory of the location of the .xcodeproj.

When you press enter, the path will appear to expand to the full path, but if you edit it again, you will see the variable. This also allows the library location to be easily changed.

Repeat for the release build. (It is possible to click on the “Header Search Path” line to enter both of these at once if you wish.)

Step 5 Add the library to the link list.

Select the Build Phases tab and open the “Link Binary With Libraries” section.

Drag the .a file from the products folder of your library into this section and that is it ready to go.

One Important Note.

The library can only be open in one xcode project window at a time.


One Response to An Xcode 4 iOS Project with a Static Library and an Application

  1. David says:

    I follow this tutorial but my app fails to build for the simulator. I had hopes that it would build for both the device and simulator. Am I missing something here?

Leave a Reply

Your email address will not be published. Required fields are marked *