[R] R - Compiling and calling Fortran code that uses IMSL libraries - Help!

Nynese Tinsley tinsley at sdac.harvard.edu
Fri Feb 12 18:11:37 CET 2010


Good Afternoon R Help!


On of my users is seriously thinking about moving to R from Splus.  In his
testing, he has already found some benefits to it.  He has, however run
into one issue, calling his Fortran functions in R.  Previously, in Splus,
he would do the following:

1. Compile via f90 the *.f program
2. link the object file to the Fortran IMSL libraries via the 'ld' command
3. start Splus and run dyn.load(*.o)
4. call function

In his research on how to do the same in R, he ran across the following
link:

http://www.stat.umn.edu/~charlie/rc/#load

In following those instructions both John and I were able to successfully:

1. run R CMD SHLIB bar.f
2. start R and run dyn.load(bar.so)
3. call function - .Fortran("bar", n=as.integer(5), x=as.double(rnorm(5)))
However the problem comes in when the following line is added to the bar.f
program file:

 call drnnor(1, x)  (This requires the Fortran IMSL Libraries)

Although the program compiles with no problem (R CMD SHLIB bar.f), we get
the following error when running dyn.load(bar.so):.

> dyn.load("bar3.so")
Error in dyn.load(x, as.logical(local), as.logical(now)) :
        unable to load shared library "/home/tinsley/tmp/bar3.so":
  ld.so.1: R.bin: fatal: relocation error: file /home/tinsley/tmp/bar3.so:
symbol drnnor_: referenced symbol not found

I have tried compiling it with f90, running ld and then running R CMD SHLIB
*.so *.o and a few other combinations with the same results.  I'm still
testing but any help you can give would be greatly appreciated.  There's a
big difference between installing, updating and maintaining R (what I do a
systems/application administrator) and using R for statistical analysis.

IMSL is included in our global library path. I created a copy of the R
startup script and added the IMSL library path to the R_LD_LIBRARY_PATH.
Ran ldd on R.bin to see if any dependencies were not found.

Is there something available in R that can do what the IMSL drnnor (double
precision random number generator) function does?

Again, any light you can shed on this would be GREATLY appreciated!


Nynese Tinsley, BSEE, MSCIS
Unix Systems Analyst
Harvard University School of Public Health
Center for Biostatistics in AIDS Research (CBAR)
651 Huntington Ave
Boston, MA 02115-6009
617-432-3244



More information about the R-help mailing list