Custom libraries on iPhone

Discussion in 'iOS Programming' started by dguisinger, Oct 12, 2008.

  1. dguisinger macrumors 6502

    Jul 25, 2002
    Alright, I'm looking for a fix to my problem.
    I've been attempting to build a library to house common Obj-C code.
    I've figured out apple doesn't allow custom frameworks, but they do seem to allow static libraries. So far so good, thats fine for me.

    The static library appears to compile fine - however, the project thats referencing it blows up during link saying it can't find the classes in the .a library file.

    I've never done static libraries in Xcode before, does anyone know how to solve this problem?
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    I haven't done this and I don't think anyone has posted how to do this but I do have an interest in figuring this out.

    There's no project template for building a static lib for the phone. There are project templates for building static libs for Mac OS X. Compare those with the phone projects.

    A few other odd comments:

    There are some .a files in the SDK that could be used for comparison.

    You can use the file and nm tools to inspect the .a files you generate.

    This guy built libcurl as a static lib for the phone using a makefile
  3. dguisinger thread starter macrumors 6502

    Jul 25, 2002
    Do you know, is there anything special one has to put in the header files to allow a ObjC class or interface to be exported in a library? (Having never written any type of framework in ObjC, maybe I'm missing something simple!)
  4. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    I think that for a static library everything is exported. It's basically just a bunch of .o files scotch-taped together.

    Look at the settings in the Cocoa-based static library template project.
  5. dguisinger thread starter macrumors 6502

    Jul 25, 2002
    Like i said, I got close to the point where the linker said objc_**** not found while linking.

    I just don't have that much experience with Gcc or xcode (nor do I want to dive into it really, I believe in having solutions that ... just work). I doubt its that hard to fix, i just don't know which setting is correct.

    I started from the OS X static framework template, and changed the CPU and OS settings to the iPhone 2.1 platform.


    suggestions, anyone?

    Right now my solution is to include source code into multiple projects, but thats dangerous because I could accidentally change a file or delete a file that is shared without thinking about it....
  6. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    I was challenged by your earlier comments so yesterday I built a static lib project. I've attached it here. It's had minimal testing. There are two projects in the archive. One builds a static lib with a single class that has a method named test. The other project includes the static lib and calls the test method. I tested it on both the Sim and device and it worked ok.

    Let me know if it works for you.

    I started with the CocoaStaticLib project and modified it to work with the iPhone SDK.

    Attached Files:

  7. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    I check-out shared files from a central SCM/CVS repository into any leaf project's directories, and make sure they're write protected.


Share This Page