building a static extension

Discussion in 'Ruby' started by Steven Jenkins, Feb 16, 2005.

  1. 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
    Steven Jenkins, Feb 16, 2005
    #1
    1. Advertising

  2. 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
    Steven Jenkins, Feb 16, 2005
    #2
    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. Bren
    Replies:
    3
    Views:
    370
  2. Dave Brueck

    Stuck building a Python extension

    Dave Brueck, Sep 24, 2003, in forum: Python
    Replies:
    3
    Views:
    303
    Daniel Dittmar
    Sep 25, 2003
  3. Carl Waldbieser
    Replies:
    7
    Views:
    951
    Carl Waldbieser
    Oct 5, 2003
  4. Christian Seberino
    Replies:
    0
    Views:
    351
    Christian Seberino
    Nov 5, 2003
  5. Midex
    Replies:
    24
    Views:
    867
Loading...

Share This Page