Luc Heinrich <lucsky / mac.com> wrote:

> /usr/local/lib/ruby/1.8/dl/import.rb:125:in `symbol': can't find the
> symbol `make_a_foo' (RuntimeError)

And to make sure we're on the same page, here's exactly what I do (this,
of course, is just a test case to reproduce a problem that I have in a
bigger project ;) ):

[ ------- foo.c ------ ]

typedef struct
{
    int bar;
    int baz;
}   FOO;

FOO make_a_foo( void )
{
    FOO foo;
    foo.bar = 42;
    foo.baz = 1;
    
    return foo;
}

[ -------------------- ]


[ ------ foo.rb ------ ]

require 'dl/import'
require 'dl/struct'

module Foo
    extend DL::Importable
    dlload 'foo.dylib'

    FOO = struct [ "int bar", "int baz" ]
    extern 'FOO make_a_foo(void)'  # this fails
    extern 'FOO make_a_foo()'      # this fails too

    def my_make_a_foo
        return FOO.new( make_a_foo )
    end

end

[ -------------------- ]

The library is compiled as a dylib (I'm on OSX) using:
$ cc -c foo.c
$ libtool -dynamic -o foo.dylib foo.o

If I then do:
$ ruby foo.rb

I get:

/usr/local/lib/ruby/1.8/dl/import.rb:125:in `symbol': can't find the
symbol `make_a_foo' (RuntimeError)
        from /usr/local/lib/ruby/1.8/dl/import.rb:144:in `import'
        from /usr/local/lib/ruby/1.8/dl/import.rb:61:in `extern'
        from foo.rb:9

-- 
Luc Heinrich - lucsky / mac.com