Including a .so like a .dll?

C

Christoph Tapler

Hi,

I'm coming from the Microsoft world and I liked the easy way how to
integrate libraries (dlls) into Ruby by using the Win32 module.

Is there any counterpart in Linux so that I can easily define the entry
points in Ruby to call routines from the so library?

I've browsed through the "Extending Ruby" chapter but it seems that it takes
much more effort (but it seems that this is a different approach).

Any idea how to do the Windows-DLL-solution on Linux ?
Thanks in advance...
Christoph
 
T

Tim Sutherland

Christoph Tapler said:
Hi,

I'm coming from the Microsoft world and I liked the easy way how to
integrate libraries (dlls) into Ruby by using the Win32 module.

Is there any counterpart in Linux so that I can easily define the entry
points in Ruby to call routines from the so library?

I've browsed through the "Extending Ruby" chapter but it seems that it takes
much more effort (but it seems that this is a different approach).

Any idea how to do the Windows-DLL-solution on Linux ?
Thanks in advance...
Christoph

Use the 'dl' library. Documentation is in the Ruby source at
ruby/ext/dl/doc/dl.txt.

This works on both Windows and Linux (and others) and is even nicer than the
Win32API module.

An example:

require 'dl/import'

module LIBC
extend DL::Importable

dlload 'libc.so.6'

typealias 'mode_t' 'unsigned int'

extern 'int mkfifo(char*, mode_t)'
extern 'void perror(char*)'
end

if -1 == LIBC.mkfifo('foo', 007)
LIBC.perror("mkfifo")
end
 
T

Tim Sutherland

Tim Sutherland wrote: said:
Use the 'dl' library. Documentation is in the Ruby source at
ruby/ext/dl/doc/dl.txt.

This works on both Windows and Linux (and others) and is even nicer than the
Win32API module.

An example:

require 'dl/import'

module LIBC
extend DL::Importable

dlload 'libc.so.6'

typealias 'mode_t' 'unsigned int'

Oops, should be
typealias 'mode_t', 'unsigned int'
extern 'int mkfifo(char*, mode_t)'
extern 'void perror(char*)'
end

if -1 == LIBC.mkfifo('foo', 007)
LIBC.perror("mkfifo")
end

I should also mention that dl supports structs and malloc in a nice way. It
is a very nice library. IMHO the best part of Ruby 1.8 is that it includes dl.
 

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
474,145
Messages
2,570,824
Members
47,371
Latest member
Brkaa

Latest Threads

Top