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

前端 未结 4 1132
孤街浪徒
孤街浪徒 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: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.

提交回复
热议问题