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”