Hello,
I am trying to link to a fortran 77 library. So far, I can call a subroutine without parameters, but fail otherwise. Here's where I'm at:
The fortran routine is very simple: accept arguments and dump them to disk. The following version accepts argument a, and writes a,b & i to disk. The initial version had no arguments, and a was set internaly. This initial version worked.
subroutine test_link (a)!a, b, i)
real a,b
integer i
b=2.0
i=1
open (10, file='call_args.txt',status='replace')
write (10,*) a, b, i
close (10)
return
end
My cffi definitions are (the routine is in the amos library):
(define-foreign-library amos
(:unix "libamos.so"))
(use-foreign-library amos)
(defctype test-link :int)
;; I got the trailing underscore by using `nm' on the library.
(defcfun "test_link_" test-link (a :float)) ; (b :float) (i :int))
(test-link- 2.0)) ; 2.0 2.1 1)
I get partial success. A call to test-link- returns 0 (not sure what that means), but the file contents are incorrect:
-3.5797695E+21 2.000000 1
i.e, instead of 2.0 I get -3.579e21.
I will be needing to call single and double reals and integers. I would also like eventually to pass single and double complex numbers.
I hear from people that linking to fortran is doable, but I have not seen simple examples.
Right now I am using gfortran. Eventually I will try intel fortran.
Thanks for your help
Mirko