Skip to content

problem of compile fortran program

2 messages · Gao Feng (FIN), Brian Ripley

#
I want to call dll from R but encounter problem in compiling the fortran
program.

First I try "Rcmd shlib prog.f", it failed and warning:

 make[1]: `libR.a' is up to date.
 make: *** No rule to make target `'prog.o', needed by `prog.a'. stop.

Then I try to compile it by absoft fortran compiler, it works and produces
prog.dll.
But when this routine is called in R, it did nothing in fact.
For example,
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20

[[2]]
[1] 0.75

[[3]]
[1] 20


What's wrong? I don't know how to deal with it.
Any suggestions would be great appreciated.

Thanks in advance.

-------FORTRAN CODE:  prog.f-------
      SUBROUTINE ARSIM_(X,NDIM,PHI)
      INTEGER NDIM
      REAL X(NDIM),PHI
      IF(NDIM.GT.1)THEN
      DO 10 I=2,NDIM
          X(I) = PHI*X(I-1)+X(I)
   10 CONTINUE
      ENDIF
      RETURN
      END
----------------------------
_              
platform i386-pc-mingw32
arch     i386           
os       mingw32        
system   i386, mingw32  
status   Patched        
major    1              
minor    5.0            
year     2002           
month    05             
day      15             
language R              

OS: win98 se
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Thu, 30 May 2002, Gao Feng (FIN) wrote:

            
No idea. When I use your example I get

[c:/TEMP]% Rcmd SHLIB prog.f
g77 -O2 -Wall  -c prog.f -o prog.o
ar cr prog.a *.o
ranlib prog.a
------- Building prog.dll from prog.a --------
echo LIBRARY prog > prog.def
echo EXPORTS >> prog.def
nm prog.a > Defs
sed -n '/^........ [BCDRT] _/s/^........ [BCDRT] _/ /p' Defs >> prog.def
rm -f Defs
gcc  --shared -s  -o prog.dll prog.def prog.a  -Lc:/R/rw1051/src/gnuwin32
-lg2c -lR
rm -f prog.def
Read ?Foreign.  The arguments should be DOUBLE PRECISION, but

.Fortran("arsim", as.single(x), as.single(phi), as.integer(20))

might work.  You've failed to match the types in Fortran and in R.