FFI with dlls compiled by MinGW

Hi,

I’m having some problems running examples of using FFI-jruby under
windows.
Until now I’ve been using it under linux without any problem. This
example
works fine under linux (both jruby and ruby), but fails in windows using
mingw to generate the dll (and using ruby 1.8.6 works fine)

Has anybody accomplished to use ffi under jruby in a mingw environment?

$ more foo.c:
int foo(int n){ return n*2; }
$ more example.rb:
require ‘rubygems’
require ‘ffi’
module Foo
extend FFI::Library
ffi_lib “./libsample.dll”
attach_function :foo, :foo, [:int], :int
end
puts Foo.foo(2)
$ gcc -c foo.c && gcc -shared -o libsample.dll foo.o
$ gcc -v
Reading specs from c:/MinGW/bin/…/lib/gcc/mingw32/3.4.2/specs
Configured with: …/gcc/configure --with-gcc --with-gnu-ld --with-gnu-as
–host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads
–disable-nls --enable-languages=c,c++,f77,ada,objc,java
–disable-win32-registry --disable-shared --enable-sjlj-exceptions
–enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm
–disable-libgcj-debug --enable-interpreter
–enable-hash-synchronization
–enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.2 (mingw-special)
$ jruby -v
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java
HotSpot™ Client VM 1.6.0_18) [x86-java]

Under windows I get an error loading the dll:

jruby example.rb
C:/jruby/lib/ruby/site_ruby/shared/ffi/library.rb:24:in `ffi_lib’:
Failed to
load library ‘libsample.dll’: Could not open library ‘libsample.dll’ :
(LoadError) No se puede encontrar el módulo especificado.
from example.rb:5

“No se puede encontrar el módulo especificado.” means “it couldn’t find
specified module”

Hi,

I think, you need a full path to the DLL on windows, not just
‘./libsample.dll’.

Like this:

DLL = File.expand_path(‘libsample.dll’, File.dirname(FILE))
ffi_lib “#{DLL}”

This one works for me.

Thanks,
–Vladimir

2010/2/1 Jesús García Sáez [email protected]:

require ‘rubygems’
Configured with: …/gcc/configure --with-gcc --with-gnu-ld --with-gnu-as
HotSpot™ Client VM 1.6.0_18) [x86-java]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Mon, Feb 1, 2010 at 09:50, Vladimir S. [email protected]
wrote:

This one works for me.

Thanks,
–Vladimir

Oh my god, you are my hero. I’ve been really crazy trying to figure out
what
is going on, I’ve even tried to compile with visual studio compiler, and
some more nonsense stuff.

Using full path works properly, thanks Vladimir

2010/2/1 Jesús García Sáez [email protected]:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs