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

Sharpie chuck at sharpsteen.net
Sat Feb 13 02:16:39 CET 2010



Nynese Tinsley wrote:
> 
> 
> 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
> 

Have you tried adding the appropriate linker flags when you invoke R CMD
SHLIB:

R CMD SHLIB *.o -L/path/to/IMSL/libraries -limsl

Seems to work for me when I build a shared library of fortran functions for
R that references routines in other shared libraries.  If I don't tell the
linker to use the other shared libraries, I get missing symbol errors
similar to the ones you described.

Oh, and make sure /path/to/libimsl.so is on LD_LIBRARY_PATH or
DYLD_LIBRARY_PATH or whichever your system uses.

Good luck!

-Charlie
-- 
View this message in context: http://n4.nabble.com/R-Compiling-and-calling-Fortran-code-that-uses-IMSL-libraries-Help-tp1482492p1493345.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list