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

前端 未结 4 1121
孤街浪徒
孤街浪徒 2020-12-13 22:55

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

相关标签:
4条回答
  • 2020-12-13 23:05

    And some more helpful advice, in terms of how to package up the result:

    Can you reference Xib files from static libraries on the iPhone?

    NB: interesting that the author of that comment says they couldn't get bundles to work with static libs. I too tried that, when I found Frameworks wouldn't work, but found that Xcode / iPhone SDK was hard-coded to prevent you from even using bundles in this way :(. I thought it might just be my mistakes, but if others have tried and failed too, then maybe not.

    0 讨论(0)
  • 2020-12-13 23:07

    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.

    0 讨论(0)
  • 2020-12-13 23:08

    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

    0 讨论(0)
  • 2020-12-13 23:11

    Sorry to be late to the game, but I recently had some help creating a static library so that people can use my data structures library on iPhone OS. See http://cocoaheads.byu.edu/code/CHDataStructures and check out from Subversion to see first-hand how I've created a static library. I haven't gone to the trouble of creating a Simulator-friendly version, but it works on the device and wasn't terribly complex.

    0 讨论(0)
提交回复
热议问题