Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How SHOULD you make (and use) static libraries on the iPhone

AFAICS, any serious iPhone developer must make and use static libs on a regular basis, or else condemn themselves to buggy, hard-to-maintain, unwieldy projects. But Apple refuses to provide any official docs on the process (just circular references: "dont do static, use dynamic! ... we don't allow dynamic on iPhone, use static!")

I have spent more than 6 months experimenting with this; I have deployed static libs in multiple iPhone apps on the App Store; I came up with a nice, working system based on Universal Binaries ... that IMMEDIATELY BROKE when OS 3.x came out (LOL); ... I now have a new system that works with all versions of the iPhone OS.

I have read the related questions on StackOverflow on this topic, and they either don't go far enough for full usage of static libs, or require you to use one or more external command-line tools, hence breaking out of the IDE. What's the point in an IDE if you can't get everything to work inside it?

I think I've found a way that works, entirely inside Xcode. But I'm really nervous, based on past experience...

I would love some feedback on whether this time - finally! - through trial and error, I've actually got it right.

OR ... even better ... I would love to find someone who will tell me exactly how you are "supposed" to do it, how Apple expects / wants / requires you to do it.

The process I have is sufficiently convoluted that I've written it up into two blog posts:

  1. First post: basic assumptions and problems
  2. Second post: methodology, and step-by-step process

PLEASE NOTE: there are many things I don't know about iPhone and Cocoa programming that I ought to; I know there's a lot wrong with what I'm doing, but I'd rather share it and possibly get shouted at than keep quiet and never learn what I'm screwing up.

Thoughts? Improvements? Or even ... am I a complete fool, and there was a much, much easier route that I was dumb enough not to notice in all my searching?

Thanks in advance...

like image 963
Adam Avatar asked Oct 14 '09 00:10

Adam


2 Answers

You may find this tutorial useful from someone who has done this recently:

http://kyleroucis.com/Kyle_Roucis/Blog/Entries/2009/10/7_Custom_Embedded_Static_Library_for_iPhone.html

like image 56
Kendall Helmstetter Gelner Avatar answered Oct 18 '22 21:10

Kendall Helmstetter Gelner


Something I missed out, because I haven't included any categories in my own static libs:

You MUST include the linker flag "-ObjC" if you use categories, or else your static lib will be "missing" some bits and pieces when you try to use it in projects.

I have heard of people placing this flag in 6 different places, but the one that seemed to work for me was:

In library project (not app project, strangely), go to build settings, and add a user-defined setting:

OTHER_CFLAGS = -DObjC

...although I believe it ought to be instead:

Other Linker Flags = -ObjC

(NB: this has the side effect of setting the OTHER_CFLAGS automagically inside the GUI)

Also, I've heard a lot of people claim it should go in the application project, but they were all embedding their projects together, not compiling true static libs, so I suspect they just got lucky.

ALSO ...

XCode / Iphone OS 3.0 seems to have a bug where you also need the -all_load flag (use exactly as with the -ObjC flag above). There's some StackOverflow questions about the use of -all_load flag with 3.0, so have a look at them for more info - I'm not really experienced with that.

like image 24
Adam Avatar answered Oct 18 '22 21:10

Adam