ruby FFI does not load DLL on Windows

I'm writing a small cross-platform C-library to do geometric calculations. I want to use this library in ruby, because it's approx five times faster than native ruby.

It works fine on Linux (Fedora 20), but when doing the same on Windows 8, it fails with the following error:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/ffi-1.9.3-x86-mingw32/lib/ffi/library.rb:133:in `block in ffi_lib': Could not open library 'libgeom': x▒K. (LoadError) Could not open library 'libgeom.dll':L
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ffi-1.9.3-x86-mingw32/lib/ffi/library.rb:100:in `map'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ffi-1.9.3-x86-mingw32/lib/ffi/library.rb:100:in `ffi_lib'
        from C:/rubytest/geom.rb:6:in `<module:Geom>'
        from C:/rubytest/geom.rb:1:in `<top (required)>'
        from main.rb:2:in `require_relative'
        from main.rb:2:in `<main>'

In the file geom.rb I have the following:

module Geom
    extend FFI::Library
    ffi_lib "libgeom"

    attach_function :point_in_rectangle, [:float, :float, :float, :float, :float, :float], :int
    # etc.
end

In the current directory I have the shared library (libgeom.so on Linux, libgeom.dll on Windows)

I'm compiling the shared library using Cygwin and the following command:

gcc -Wall -shared geom.c -o libgeom.dll

I've tried using a complete path for the library, and also tried adding the current directory to PATH, but it makes no difference.

I'm using ruby version:

ruby 1.9.3p545 (2014-02-24) [i386-mingw32]

I'm new to ruby, but was very happy with the immediate success on Linux. Now I just want to get it working on Windows too.

Can you suggest any work-around?

Is this a problem with 32-bit versus 64-bit?

Upvotes: 1

Views: 1883

Answers (1)

I've figured it out myself :-)

The reason is that my ruby-version is 32-bit, while my Cygwin is 64-bit.

I've now removed Cygwin and changed to 32-bit Cygwin, and now it works!

Upvotes: 1

Related Questions