Hello,<br><br>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:<br><br>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.<br>
<br> subroutine test_link (a)!a, b, i)<br><br> real a,b<br> integer i<br><br> b=2.0<br> i=1<br> open (10, file='call_args.txt',status='replace')<br> write (10,*) a, b, i<br>
close (10)<br> return<br> end <br><br>My cffi definitions are (the routine is in the amos library):<br><br>(define-foreign-library amos<br> (:unix "libamos.so"))<br><br>(use-foreign-library amos)<br>
<br>(defctype test-link :int)<br><br>;; I got the trailing underscore by using `nm' on the library.<br>(defcfun "test_link_" test-link (a :float)) ; (b :float) (i :int))<br><br>(test-link- 2.0)) ; 2.0 2.1 1)<br>
<br>I get partial success. A call to test-link- returns 0 (not sure what that means), but the file contents are incorrect:<br> -3.5797695E+21 2.000000 1<br>i.e, instead of 2.0 I get -3.579e21.<br><br>I will be needing to call single and double reals and integers. I would also like eventually to pass single and double complex numbers.<br>
<br>I hear from people that linking to fortran is doable, but I have not seen simple examples. <br><br>Right now I am using gfortran. Eventually I will try intel fortran.<br><br>Thanks for your help<br><br>Mirko<br>