[Ruby] Native extensions on OS X

Aaron Patterson aaron at tenderlovemaking.com
Mon Jul 9 07:53:07 PDT 2007


On Mon, Jul 09, 2007 at 07:26:40AM -0700, Aaron Patterson wrote:
> On Mon, Jul 09, 2007 at 08:57:07AM -0700, Eric Hodel wrote:
> > On Jul 8, 2007, at 19:21, Aaron Patterson wrote:
> > 
> > > Alright, I'm not sure what I'm doing wrong....
> > >
> > > I'm writing a native extension that loads a shared object.  But for  
> > > some
> > > reason, it can't find the symbols from the shared object!  Everything
> > > works on linux, but for some reason OS X doesn't seem to work.
> > >
> > > Here's my compile output:
> > >
> > > [aaron at aaron-pattersons-powerbook58 ext]$ make
> > > gcc -fno-common  -arch ppc -g -Os -pipe -fno-common  -arch ppc - 
> > > pipe -pipe -fno-common  -I. -I/usr/lib/ruby/1.8/powerpc-darwin8.0 - 
> > > I/usr/lib/ruby/1.8/powerpc-darwin8.0 -I. -DHAVE_LAME_LAME_H  -c  
> > > decoder.c
> > > gcc -fno-common  -arch ppc -g -Os -pipe -fno-common  -arch ppc - 
> > > pipe -pipe -fno-common  -I. -I/usr/lib/ruby/1.8/powerpc-darwin8.0 - 
> > > I/usr/lib/ruby/1.8/powerpc-darwin8.0 -I. -DHAVE_LAME_LAME_H  -c  
> > > get_audio.c
> > > gcc -fno-common  -arch ppc -g -Os -pipe -fno-common  -arch ppc - 
> > > pipe -pipe -fno-common  -I. -I/usr/lib/ruby/1.8/powerpc-darwin8.0 - 
> > > I/usr/lib/ruby/1.8/powerpc-darwin8.0 -I. -DHAVE_LAME_LAME_H  -c  
> > > lollame.c
> > > gcc -fno-common  -arch ppc -g -Os -pipe -fno-common  -arch ppc - 
> > > pipe -pipe -fno-common  -I. -I/usr/lib/ruby/1.8/powerpc-darwin8.0 - 
> > > I/usr/lib/ruby/1.8/powerpc-darwin8.0 -I. -DHAVE_LAME_LAME_H  -c  
> > > syncword.c
> > > cc -dynamic -bundle -undefined suppress -flat_namespace  -L"/usr/ 
> > > lib" -o lollame.bundle decoder.o get_audio.o lollame.o syncword.o  - 
> > > lpthread -ldl -lobjc
> > >
> > >
> > > When I run my test script:
> > >
> > > dyld: NSLinkModule() error
> > > dyld: Symbol not found: _lame_get_num_channels
> > >   Referenced from: ./lollame.bundle
> > >   Expected in: flat namespace
> > >
> > > Trace/BPT trap
> > >
> > > My dlopen line from my code:
> > >
> > >     dlopen("libmp3lame.dylib", RTLD_NOW | RTLD_GLOBAL);
> > >
> > > Does anyone have any ideas with what might be wrong?
> > 
> > Is it static?  I always get that wrong.
> > 
> > nm lollame.bundle | grep -i ' t '
> > 
> > Big T is dynamically linkable.  Little t is not.
> 
> I don't think so....  lame_get_num_channels is defined in
> libmp3lame.bundle:
> 
> [aaron at amac ext]$ nm /usr/local/lib/libmp3lame.dylib | grep -i ' t ' | grep get_num_channels
> 00033cd5 T _lame_get_num_channels
> 
> I tried running ktrace on the process, and I don't see it open
> libmp3lame.dylib.  It seems like its trying to resolve symbols before I
> load my shared object!

I got it working.  I took Evan's advice and linked against the .so, and
everything is fine now!

-- 
Aaron Patterson
http://tenderlovemaking.com/


More information about the Ruby mailing list