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.
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
- Make sure your static library project is not opened by Xcode
- Open your HelloLibrary project, drag your static library project MyLibrary into the Project Navigator of the HelloLibrary project.
- 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.
- 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.
- 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.
- Finally you should be able to compile your HelloLibrary without an error!