Ruby Extensions using OS X Frameworks

D

David Craine

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
 
D

Dave Baldwin

You could try adding

$LDFLAGS = '-framework AddressBook'

into you extconf.rb file.

Dave.
 
D

David Craine

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:[email protected]]
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.
 
M

Michal 'hramrach' Suchanek

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
 
D

David Craine

--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.




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--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top