TechNote 2 – Sharing Libraries Across Projects

This tech note describes a way to share code and libraries across multiple iPhone app projects. It describes how to set up a project in Xcode to depend on static libraries compiled in a separate project (in this case Cocos2d). It is basically a bullet point summary of the excellent article by Clint Harris.

First, if you haven’t already done so, set up your Xcode global settings as described in TechNote 1.

Then

  1. Open the Source Tree tab of the Xcode preferences.
  2. Add a new setting with a Setting/Display name of COCOS2D_SRC and a path to that project e.g. /Users/rob/workspace/iphone/cocos2d-iphone-0.99.0

Then, set up project specific settings:

  1. Add the Cocos2d project (cocos2d-iphone.xcodeproj) to the current project (Option+Cmd+A). Do not copy.
  2. On the newly added project, edit the Info (Cmd+i). Change “Path Type” to be Relative to COCOS2D_SRC.
  3. Edit the Info (Cmd+i) of the main Target.
    • General Tab: Add (“+”) libs to “Direct Dependencies” (cocos2d, Chipmunk, CocosDenshion)
    • Build Tab: Add $(COCOS2D_SRC) (with Recursive) to “User header search paths”. Ensure “Library Search Paths” is empty.
      Note: Ensure you do this for Release and Debug (or both at the same time). I initially just did Debug by mistake and it took a while to work out why my Release wouldn’t compile!
  4. Drag libs (libcocos2d.a etc) from newly added cocos2d project to “Link Binary with Libraries” in your Target.
    (Note that this step is only required for the “final”app project. See TechNote 6 for more details on creating your own static libraries.)

That’s it. If it doesn’t work, go through the article mentioned above, step by step.
(Note, you may need to add the image fps_images.png to your Resources)


Leave a Reply

You must be logged in to post a comment.