Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode can't add static library

I have created a large framework which I intend to use in several apps that I will be creating, however I cannot figure out how to create and import a static library. I have been following this tutorial, as it seems to be most up to date I can find

http://www.icodeblog.com/2011/04/07/creating-static-libraries-for-ios/

The tutorial says after creating the static library, and copying the .a file into the folder along with the .h files;

Now, just drag this folder into the project and Xcode will set up 
all of the linking automagically.

However, when I copy that folder across into xCode, the folder is blue, and I cannot import any of the files

I then tried this tutorial

http://www.blog.montgomerie.net/easy-xcode-static-library-subprojects-and-submodules

I managed to get it to import the sample project like this

   #import  <SampleSubproject/SampleSubproject.h>

But I can't import the any of the other files in the library.

I have been at this hours, and I cannot seem to find a simple concise tutorial that explains how to actually add a static library properly, there seems to be so many different ways of doing it. Could someone please show me the easiest way to go about doing this.

Also I have heard that static libraries don't compile in the iOS simulator, is this true?

Thanks in advance

like image 244
AdamM Avatar asked Nov 03 '22 06:11

AdamM


1 Answers

Xcode 4 will not let you drag a folder of files in. It will just fail. You should create a Group (Xcode folder) within Xcode first, then you can drag and drop the files in that way.

Another option is to copy the folder to the projects root folder and then drag/drop the files into Xcode and create a reference to the files rather than having Xcode copy/paste them wherever it feels like.

Static libraries are not compiled for devices or simulator. They are precompiled when they are created or built. The references are built into your project, but the library isn't re-built when you compile your code.

One other thing to consider, Xcode 4 handles creating static libraries much different. Before, Xcode 3, a static library would be compiled into 1 large universal static lib that handles both device and simulator. Now, that default action is not done. You can still do this via build scripts that will package them together the way they need, but is it not default action. The developer in charge of the static library would have to do this. So if you get your source this way from 3rd party devs, make sure you understand how the library is built.

like image 119
Bill Burgess Avatar answered Nov 15 '22 05:11

Bill Burgess