Linking an iOS Static Library Project in another Project in Xcode 4.3.2

It took me a while searching on the Internet. Most of the information I found was using the old version of Xcode which has it’s interface changed already. Anyway at the end I figured out a satisfactory way to link a static library project.

Assumption

Some assumptions before the following procedure:

  • You have already created a static library called MyLibrary
  • You are going to use the static library MyLibrary in another iPhone project HelloLibrary
  • You want to link the static library by using project with source code but not binary with header files
  • You already placed your project files in the layout shown in the following screenshot
Folder Layout

Folder Layout

Procedure

  1. Make sure your static library project is not opened by Xcode
  2. Open your HelloLibrary project, drag your static library project MyLibrary into the Project Navigator of the HelloLibrary project.
  3. In your source code, include the header files that you need from the MyLibraryproject. When you compile your project you should receive an error complainting missing header file.

    Project Navigator & Missing Header File Compile Error

    Project Navigator & Missing Header File Compile Error

  4. Now go to your project property page, under the target select HelloLibrary, Build Settings tab, click the All button instead of Basic button under the tab to show all available settings. Scroll down the setting list and look for the section Search Paths. Expand the Header Search Paths item and add the path so that Xcode is able to search the header file from our MyLibrary static library. In our case, the path would be ./Library.

    Configure Header Search Paths

    Configure Header Search Paths

  5. Finally, remember to add the MyLibrary static library in Target Dependencies and Link Binary With Libraries under the Build Phases tab. If you forgotten to do that you will receive a compile error of undefined symbol.

    Edit 2012-07-27: If MyLibrary you are including is using some other frameworks or libraries, for example MessageUI.framework, be sure to include these frameworks and libraries to your project as well! Also, you will need to copy all the related resources such as images used by MyLibrary or else your program will complaint about the missing resources. iOS Library only contains compiled source code and header file.

    Configure Target Dependencies & Link Binary With Libraries

    Configure Target Dependencies & Link Binary With Libraries

    Compile Error - Undefined Symbol

    Compile Error – Undefined Symbol

  6. Finally you should be able to compile your HelloLibrary without an error!
Advertisements

8 responses to “Linking an iOS Static Library Project in another Project in Xcode 4.3.2

  1. Thanks for this! My project broke in Xcode 4.3, I was struggling to figure out how to fix it. Worked like a charm.

  2. When I tried this article I got the last screen compilation error.Can you please tell me how to resolve this error

        • I just tested it on Xcode, and I guess I have missed a point.

          If the library you are including is using some other frameworks or libraries (for example the library use MessageUI.framework), then you have to include these frameworks and libraries to your project as well!

          • Hi,just I create a static library for displaying text and I use this library file in another project.which frame work I need to create here?

          • The frameworks you need to include in your another project would be the frameworks used in your static library for displaying text. I cannot know what frameworks or libraries you used in your static library for displaying text so I cannot give you the exact framework names.

            If it is possible maybe you can also post the error message here to give me more hints on what framework you might be needed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s