building a static extension

S

Steven Jenkins

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:
libcradleapi.so.0: cannot open shared object file: No such file or directory

libcradleapi.so.0 is the vendor library, not the wrapper code. I renamed
all libcradleapi.so* 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'
dir_config('cradleapi')
if have_library('cradleapi')
create_makefile('cradle')
else
File.open('Makefile', 'w') do |f|
f.puts('all:')
end
end

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.

Steve
 
S

Steven Jenkins

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.

Steve
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top