How to use Fiddle to call .dylib

Hi,

I used DL to call intel fortran .dylib file successfully before, but DL
is
removed from
latest Ruby version. I tried to use fiddle and got error message
“unknown
symbol
‘samplesize’”, could anyone help to see where I did wrong? Thanks!

Liz

my fortran function is below (our_int is compatible with long in C,
our_double is compatible with
double in C):

integer(our_int) function samplesize( maxn, delta, conf, errmsg )
result(
answer )
!DEC$ ATTRIBUTES DLLEXPORT :: samplesize
!
! OUTPUT
! N: sample size
!
! EXAMPLE
! samplesize4(3000, .2, .90);
!

implicit none

integer(our_int), intent(in) :: maxn
real(our_dble), intent(in) :: delta, conf
character(len=err_msg_width), intent(out) :: errmsg

and I used DL to call it like this before:

require ‘dl’
require ‘pathname’
sspath = Pathname.new( “#{RAILS_ROOT}/lib/libsamplesize.dylib” )
ss = DL.dlopen( sspath )
samplesize = ss[ “samplesize_”, “iiddS” ]
session[:errmsg] =
"
";
session[:n], args = samplesize[ session[:nmax], session[:delta],
session[:conf], session[:errmsg] ]

Now I tried to use fiddle as below:

require 'fiddle'
  libm = Fiddle.dlopen(

“/Library/WebServer/smart/lib/libsamplesize.dylib” )

samplesize = ss[ “samplesize_”, “iiddS” ]

samplesize=Fiddle::Function.new(libm[‘samplesize’],[Fiddle::TYPE_LONG,Fiddle::TYPE_DOUBLE,Fiddle::TYPE_DOUBLE,Fiddle::TYPE_VOIDP],Fiddle::TYPE_LONG)
session[:errmsg] =
"
";

session[:n], args = samplesize[ session[:nmax],

session[:sigma_sq],

session[:delta], session[:conf],

session[:errmsg] ]
session[:n] = samplesize.call( session[:nmax], session[:delta],
session[:conf], session[:errmsg] )

but I got error:

unknown symbol “samplesize”
Extracted source (around line #34):

323334353637

   libm = Fiddle.dlopen( 

“/Library/WebServer/smart/lib/libsamplesize.dylib” )

samplesize = ss[ “samplesize_”, “iiddS” ]

  samplesize=Fiddle::Function.new(libm['samplesize'],[Fiddle::TYPE_LONG,Fiddle::TYPE_DOUBLE,Fiddle::TYPE_DOUBLE,Fiddle::TYPE_VOIDP],Fiddle::TYPE_LONG)
  session[:errmsg] = " 

";

session[:n], args = samplesize[ session[:nmax],

session[:sigma_sq],

session[:delta], session[:conf],

session[:errmsg] ]

Rails.root: /Library/WebServer/smart
Application Trace
http://calder229.hhdev.psu.edu/smart/samplesize/compute#
| Framework Trace http://calder229.hhdev.psu.edu/smart/samplesize/compute#
| Full Trace http://calder229.hhdev.psu.edu/smart/samplesize/compute#

app/controllers/samplesize_controller.rb:34:in []' app/controllers/samplesize_controller.rb:34:in compute’

It seems not many people using Ruby to call Fortran .dylib, anyway, I
figured that I need to wrap Fortran
with C…