Ruby Extensions using OS X Frameworks

Discussion in 'Ruby' started by David Craine, Dec 22, 2004.

  1. David Craine

    David Craine Guest

    I'm trying to write a ruby extension which accesses the
    AddressBook.framework on OS X. I can get the extension to compile but
    get undefined symbol errors for each of the AddressBook APIs when I
    load the extension. It's pretty clear that it's not able to find the
    AddressBook library module, but I'm not quite sure how to tell it where
    to look. Anyone have any experience with accessing OS X frameworks in
    this way?

    Dave Craine
    InfoEther
    David Craine, Dec 22, 2004
    #1
    1. Advertising

  2. David Craine

    Dave Baldwin Guest

    You could try adding

    $LDFLAGS = '-framework AddressBook'

    into you extconf.rb file.

    Dave.

    On 22 Dec 2004, at 15:06, David Craine wrote:

    > I'm trying to write a ruby extension which accesses the
    > AddressBook.framework on OS X. I can get the extension to compile but
    > get undefined symbol errors for each of the AddressBook APIs when I
    > load the extension. It's pretty clear that it's not able to find the
    > AddressBook library module, but I'm not quite sure how to tell it
    > where to look. Anyone have any experience with accessing OS X
    > frameworks in this way?
    >
    > Dave Craine
    > InfoEther
    >
    >
    Dave Baldwin, Dec 22, 2004
    #2
    1. Advertising

  3. In case it is of help, RubyCocoa is able to access the Address Book.
    See:

    http://www.fobj.com/rubycocoa/doc/faq.en.html

    I haven't tested it myself though.

    Marshall


    On Dec 22, 2004, at 7:06 AM, David Craine wrote:

    > I'm trying to write a ruby extension which accesses the
    > AddressBook.framework on OS X. I can get the extension to compile but
    > get undefined symbol errors for each of the AddressBook APIs when I
    > load the extension. It's pretty clear that it's not able to find the
    > AddressBook library module, but I'm not quite sure how to tell it
    > where to look. Anyone have any experience with accessing OS X
    > frameworks in this way?
    >
    > Dave Craine
    > InfoEther
    >
    Marshall Elfstrand, Dec 22, 2004
    #3
  4. David Craine

    David Craine Guest

    Thanks Dave. That got me past the initial linking error. I am getting
    another linking error apparently when it tries to lookup NSObject. I tried
    adding "-framework Foundation.framework" to the LDFLAGS setting as well but
    that didn't seem to help. Any additional thoughts?

    Dave

    -----Original Message-----
    From: Dave Baldwin [mailto:]
    Sent: Wednesday, December 22, 2004 10:48 AM
    To: ruby-talk ML
    Subject: Re: Ruby Extensions using OS X Frameworks

    You could try adding

    $LDFLAGS = '-framework AddressBook'

    into you extconf.rb file.

    Dave.

    On 22 Dec 2004, at 15:06, David Craine wrote:

    > I'm trying to write a ruby extension which accesses the
    > AddressBook.framework on OS X. I can get the extension to compile but
    > get undefined symbol errors for each of the AddressBook APIs when I
    > load the extension. It's pretty clear that it's not able to find the
    > AddressBook library module, but I'm not quite sure how to tell it
    > where to look. Anyone have any experience with accessing OS X
    > frameworks in this way?
    >
    > Dave Craine
    > InfoEther
    >
    >
    David Craine, Dec 31, 2004
    #4
  5. On Thu, Dec 23, 2004 at 12:06:04AM +0900, David Craine wrote:
    > I'm trying to write a ruby extension which accesses the
    > AddressBook.framework on OS X. I can get the extension to compile but
    > get undefined symbol errors for each of the AddressBook APIs when I
    > load the extension. It's pretty clear that it's not able to find the
    > AddressBook library module, but I'm not quite sure how to tell it where
    > to look. Anyone have any experience with accessing OS X frameworks in
    > this way?


    Generally you need to link in the framework with some flag (probably
    -framework <framework> or -Wl,-framework -Wl,<farmework>) during link.
    Since LDFLAGS are not supported you should put this to DLDFLAGS.

    You can try to build the extension with the ruby from fink which does
    not suppress undefined symbols and would not link an extension without
    the required libraries.

    HTH

    Michal Suchanek
    Michal 'hramrach' Suchanek, Jan 3, 2005
    #5
  6. David Craine

    David Craine Guest

    --Apple-Mail-2--227269321
    Content-Transfer-Encoding: 7bit
    Content-Type: text/plain;
    charset=US-ASCII;
    format=flowed

    Thanks for the help. I've actually used the -framework option to
    specify the AddressBook framework, and I'm able to compile, however,
    when I try to use the extension in a test script I get the following
    errors:

    objc: failed objc_getClass(NSObject) for ABAllGroup->isa->isa
    objc: please link appropriate classes in your program
    Trace/BPT trap


    Here is the output generated by the make file:

    gcc -fno-common -g -O2 -pipe -I.
    -I/usr/local/lib/ruby/1.8/powerpc-darwin
    -I/usr/local/lib/ruby/1.8/powerpc-darwin -I. -c RubyABWrapper.c
    cc -dynamic -bundle -undefined suppress -flat_namespace -framework
    AddressBook -framework Carbon -L"/usr/local/lib" -o AddressBook.bundle
    RubyABWrapper.o -ldl -lobjc
    ld: warning -prebind has no effect with -bundle

    I'm specifying both the AddressBook framework and the Carbon Framework.
    The hangup appears to be in locating the library that has the
    NSObject, which is somewhat confusing to me because my extension is
    built to use the C API for the AddressBook and not the Objective-C API.
    Below is the code for the extension (it's short because I'm just
    trying to test it out right now):

    #include "ruby.h"
    #include <AddressBook/ABAddressBookC.h>
    #include <AddressBook/ABGlobalsC.h>

    VALUE abWrapper;
    ABAddressBookRef sharedABRef;

    static VALUE t_init(VALUE self)
    {
    //add other initialization code here
    sharedABRef= ABGetSharedAddressBook();
    return self;
    }

    static VALUE t_getMe(VALUE self)
    {
    ABPersonRef personRef;

    personRef = ABGetMe(sharedABRef);
    }

    void Init_RubyABWrapper()
    {
    abWrapper = rb_define_class("RubyABWrapper", rb_cObject);
    rb_define_method(abWrapper, "initialize", t_init, 0);
    rb_define_method(abWrapper, "getMe", t_getMe, 0);
    }

    I've created a simple test script that looks like this:

    require 'AddressBook'

    t = RubyABWrapper.new
    t.getMe

    The objc: failed objc_getClass(NSObject) for ABAllGroup->isa->isa error
    seems to occur when the AddressBook extension is loaded since I can
    comment out the remaining lines of the script and the error still
    occurs.

    Again, any help/insights would be greatly appreciated.

    Dave C.




    On Jan 3, 2005, at 7:09 AM, Michal 'hramrach' Suchanek wrote:

    > On Thu, Dec 23, 2004 at 12:06:04AM +0900, David Craine wrote:
    >> I'm trying to write a ruby extension which accesses the
    >> AddressBook.framework on OS X. I can get the extension to compile but
    >> get undefined symbol errors for each of the AddressBook APIs when I
    >> load the extension. It's pretty clear that it's not able to find the
    >> AddressBook library module, but I'm not quite sure how to tell it
    >> where
    >> to look. Anyone have any experience with accessing OS X frameworks in
    >> this way?

    >
    > Generally you need to link in the framework with some flag (probably
    > -framework <framework> or -Wl,-framework -Wl,<farmework>) during link.
    > Since LDFLAGS are not supported you should put this to DLDFLAGS.
    >
    > You can try to build the extension with the ruby from fink which does
    > not suppress undefined symbols and would not link an extension without
    > the required libraries.
    >
    > HTH
    >
    > Michal Suchanek
    >
    >


    --Apple-Mail-2--227269321--
    David Craine, Jan 3, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phillip B Oldham
    Replies:
    7
    Views:
    306
    Fred Pacquier
    Oct 1, 2008
  2. Brian McCallister

    Ruby web-application frameworks

    Brian McCallister, Jul 29, 2003, in forum: Ruby
    Replies:
    0
    Views:
    92
    Brian McCallister
    Jul 29, 2003
  3. hsun
    Replies:
    2
    Views:
    86
    Brian McCallister
    Aug 18, 2005
  4. David Brady
    Replies:
    2
    Views:
    102
    Florian GroƟ
    Sep 3, 2005
  5. Softmind Technology
    Replies:
    0
    Views:
    76
    Softmind Technology
    Jan 8, 2008
Loading...

Share This Page