How do I use a library that was written in Objective-C from a C program?

Discussion in 'Mac Programming' started by moonman239, Apr 27, 2014.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I just finished building an Objective-C library that uses the Core Location framework. Now I want to take that library and use it in a C program. I'm just building the C program so that I can then use the library to extend Ruby.

    Right now, I just want to learn enough C to accomplish this particular task.
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    You need an Objective-C runtime for the code to work. If you want Ruby to call Objective-C:
    http://en.m.wikipedia.org/wiki/RubyCocoa#How_to_call_Objective-C_methods_from_Ruby

    If you want C to get you there, just keep in mind you're really writing an Objective-C program, it just happens you stuck with straight C for some methods. Eventually, either with []s or objc_msgsend you're going to pass an Objective-C.

    -Lee
     
  3. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #3
    Thanks.

    Edit: The documentation makes it seem like RubyCocoa is for developing apps, not Ruby extensions.
     
  4. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #4
    I'm thinking that writing a scriptable command-line tool would be as good of a solution as, if not better than, using RubyCocoa.

    I think that I could build a tool that uses all of the native frameworks I want to use and has an AppleScript API that I can later invoke in Ruby.

    Here's the thing. I want to be able to use the library in a command-line program. The library does not need a GUI to function.
     
  5. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #5
    Unless your library is plain C you will need the Objective-C runtime, GUI or not.

    You can certainly write an Objective-C command-line app, then interact with it however you'd like. I'm not totally clear where AppleScript gets involved here. It seems to up the complexity. I assume your Ruby code could just invoke the command line tool directly.

    -Lee
     

Share This Page