From: Eric Hodel Date: 2005-03-24T06:10:07+09:00 Subject: Re: Stack, Struct and DL --Apple-Mail-13-160996181 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed On 23 Mar 2005, at 12:59, Luc Heinrich wrote: > Luc Heinrich 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 ;) ): You'll have to teach DL what type FOO is. Unfortunately, DL doesn't barf on you in a friendly way when it can't recognize a type. > [ ------ foo.rb ------ ] > > require 'dl/import' > require 'dl/struct' > > module Foo > extend DL::Importable > dlload 'foo.dylib' typealias "FOO", "void *" Something like this should do it. (Yeah, void * is probably the wrong type, see dl/types for what types dl knows about.) > 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 > -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --Apple-Mail-13-160996181 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (Darwin) iD4DBQFCQdsWMypVHHlsnwQRAtJQAJQMBNYH5g2hNqNQup0HxunDnzXHAJ9SpzPe DUsrTMKdWPkDBDFh8o9OpQ== =Kb66 -----END PGP SIGNATURE----- --Apple-Mail-13-160996181--