In article <408428ea$0$29350$3b214f66 / aconews.univie.ac.at>, Christoph Tapler
wrote:
>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