libr

How to add a static library to iOS project in Xcode 4

Static library to iOS

After struggling for a while to include CHDataStructures to my iOS project, here’s a step by step guide that will allow you to add any static library without losing your mind.

STEP 1: Add the static library sources to a Source Tree
Go to XCode preferences and select the Source Trees tab, add a new source tree whereas the name and display name are WHATEVER_LIB_SRC and the path is the full path to the source code.
STEP 2: Add the static library project to your client project
Select your client project and form the popup menu choose Add Files to project. Select the static lib project and add. Make sure you don’t copy, just reference them. The Static Lib project should now be a subproject.
STEP 3: Make sure the library is also compiled when we build our project
We need to modify our application target. Select your application target and the Build Phases tab. Open the Target Dependencies group and add the library (libXXX.a file).
Go to the Build Settings and modify the User Header Search Paths. Double click on the value and type   $(WHATEVER_LIB_SRC). Make sure to check the recursive option.
STEP 3.a: Modify the User Header Search Paths at the project level
Select your project and go to the Build Settings and modify the User Header Search Paths. Double click on the value and type   $(WHATEVER_LIB_SRC). Make sure to select the recursive option.
STEP 4: Make sure your static lib is linked to the main exe
Select your application target and the Build Phases tab. Open the Link Binary With Libraries and add the static library.
You’re done.

Acerca de Fernando Rodriguez

Fundador & Editor Jefe de justcodeit, Fernando Rodríguez (@frr149 & Linkedin) es desarrollador & un experto en la enseñanza de máxima calidad en programación y desarrollo para dispositivos iOS, Cocoa Touch, Objective C, Swift, Python, entre otros, aunque su mejor carta de presentación, es la opinión de sus alumnos: http://keepcoding.io/es/testimonio/ CLO en KeepCoding & Arunovo. Instructor de iOS Avanzado del Big Nerd Ranch. Profesor Asociado de la U-tad, autor invitado de revistas como iPhoneWorld, Applesfera.com & ponente habitual en conferencias dentro y fuera de España (iOSDevUK, CodeMotion, BCNDevCon, etc). En sus vidas anteriores fue un nerd de Python y Django, mago de Smalltalk, y para su pesar, galeote de C++ y un gran cocinero.

Share this:

Leave a comment