Building a static extension

I have a vendor-supplied library and some SWIG-generated wrapper code for it. The vendor supplies both a static (.a) and dynamic (.so) library. Platform is Gentoo Linux (kernel 2.6.10).

I have (mostly) successfully built an extension using the standard mkmf technique. I can load the library and run simple Ruby scripts using it. On more complex scripts, however, Ruby crashes with a segfault.

On closer examination, it turns out that the vendor library is doing things you shouldn't do in a shared library. (They don't normally provide the shared library; they did it for me because I wanted to build an extension.) I can cause the same crash using a C example. It works fine with the static library.

So, I'm trying to build Ruby with a static extension. I followed the steps in the Pickaxe: edited ext/Setup, moved my extension code into ext/jpl/cradle, and did 'make clean all install'. Everything appears to work, but when I try to start Ruby, it fails with

/tmp/ruby-1.8.2/bin/ruby: error while loading shared libraries: cannot open shared object file: No such file or directory is the vendor library, not the wrapper code. I renamed all* and re-ran ldconfig before compiling Ruby, so I have no idea why it's trying to load the dynamic library.

Here's my extconf.rb:

require 'mkmf'
if have_library('cradleapi')
else'Makefile', 'w') do |f|

The conditional is there because this extension is an optional part of a bigger package. Is there some magic I need to add to make it link against libcradleapi.a?

Any help appreciated.


Sigh. Never mind.

I ran configure with --prefix to build in a sandbox. The last time I ran configure, I mis-typed the prefix. So all my test were running against an old version, which is known to not work :-).

At least it works now. Sorry about the wasted bandwidth.