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

Contenido del Bootcamp Dirigido por: | Última modificación: 12 de marzo de 2024 | Tiempo de Lectura: 1 minutos

Algunos de nuestros reconocimientos:

Premios KeepCoding

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, I will teach you how to add library in xcode

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 ( xcode build static library ). Open the Target Dependencies group and add the ios 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.
Fernando Rodríguez

iOS Developer & Co-Fundador de KeepCoding

Posts más leídos