How to install static frameworks on Xcode 4
I had some issues installing OCMock on Xcode 4, and found the method to be documented differently in a number of places. Fortunately I’ve worked out how to do it and it can be applied to any static framework, so I’m sharing it here, using OCMock as an example.
Download the framework and locate the .a and header files
Download the distribution files for the framework (for OCMock it comes as a dmg) and locate the .a and header files.
Here’s mine on my desktop:
Copy these files into your source folder for your Xcode project
- Make a subfolder in the root of your project folder named ‘Libraries’ (or place it where you wish – I’ll refer to this as {LIBRARIES FOLDER})
- Make a subfolder in this with the name of your Framework, e.g. OCMock – I’ll call this {FRAMEWORK FOLDER}
- Copy the contents of your static framework in here, preserving the original folder structure
When you are done your structure should look something like this:
Create references to the files in Xcode 4
To set up references to these new files:
- Create a new folder in Frameworks called the same as {FRAMEWORK FOLDER}
- Drag all the files inside your actual {FRAMEWORK FOLDER} into this one
- Deselect “Copy items to your destination folder”
- Select the targets you need – in OCMock case it will be the Unit Tests, but generally it will be the main target
You should now see the framework listed.
My project folder now looks like this:
I’ll add any more headers from other Frameworks in subgroups with the name of the framework.
Add your header search path to the target build settings
- Select the target you added the framework for, in my case, “FrameworkInstallTests”.
- Select the “Build Settings” tab
- Search for “header search paths”
- Locate “Header Search Paths” field
- Double click the field
- Check the “recursive” box
- Add this to the settings:
- $(PROJECT_DIR)/Libraries
Add linker flag
- Select the target you added the framework for, in my case, “FrameworkInstallTests”.
- Select the “Build Settings” tab
- Search for “linker flags”
- Locate “Other Linker Flags” field
- Double click the field
- Add this:
- -force_load $(PROJECT_DIR)/Libraries/{FRAMEWORK FOLDER}/{YOUR FRAMEWORK NAME}.a
- Which should be the full path to the .a file for the framework, e.g. “$(PROJECT_DIR)/Libraries/libOCMock.a”
Restart Xcode and you should be done!
Restart Xcode.
Leave any issues in the comments and I’ll see what I can do.
-
Erik





