Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking a static library to an iOS project in Xcode 4

I have a project (AQGridView) that compiles to a static library, but I can't seem to add it to my project.

Dragging in the project to my project creates a workspace, and if I try to link the libAQGridView.a file from the DerivedData directory it doesn't recognize it as a library. I'm not sure what I'm doing wrong.

This is the AQGridView project. Does anyone know specifically how to use it in an Xcode 4 project?

like image 618
Matt Hudson Avatar asked May 25 '11 12:05

Matt Hudson


People also ask

How do I create a static library in Xcode?

Open XCode and start a new project. Under iOS, select Library and “Cocoa Touch Static Library” say it as "staticlibrary". This will create a nice new project for us that builds a . a file.

Does swift support static libraries?

As mentioned, Apple does allow Swift in static libraries as of Xcode 9 Beta 4.


1 Answers

I do this as follows:

  1. Drag in the static library project. If you have the static library project open in Xcode, close it now.
  2. Select the main project in the project navigator (the project I'm adding the static library to) and in the editor, under the header TARGETS in the left-hand column, select my main project's target and navigate to the Build Phases tab.
  3. Click the "+" for Target Dependencies and add the library icon target dependency from the added static library project.
  4. Click the "+" for Link Binary with Libraries and add the library icon that is under the folder "Workspace".
  5. It may also be necessary to enter a Header Search Path for the headers of the static library project if that is how the headers are linked in the static library project itself.

If you don't see the static library project as nested under the main project in the main project's project navigator, the most likely reason for that is that the static library's own Xcode project is still open. Quit Xcode and open up the main project that has the nested static library project in it without opening up the original static library project itself, and you should see it appearing as a nested project in your main project.

like image 190
Halle Avatar answered Sep 29 '22 13:09

Halle