StevenMurray
StevenMurray

Reputation: 752

R won't call gfortran compiled object?

I made a simple fortran routine

subroutine add(x,y)
    real(8) :: x,y

    y = x + 3
end subroutine

saved as test.f90.

I compile with

gfortran -shared test.f90 -o test.so

In R (in the same directory), I use

dyn.load('test.so')

but it gives me this error:

Error in dyn.load("test.so") : 
  unable to load shared object '/Users/Steven/Documents/PhD/npsR/test.so':
  dlopen(/Users/Steven/Documents/PhD/npsR/test.so, 6): Symbol not found: ___addtf3
  Referenced from: /usr/local/gfortran/lib/libquadmath.0.dylib
  Expected in: /Library/Frameworks/R.framework/Resources/lib/libgcc_s.1.dylib
 in /usr/local/gfortran/lib/libquadmath.0.dylib

Does anyone know why? I'm using mac osx Lion, with R v2.15.0 and gfortran 4.6.2.

Thank you!

Upvotes: 2

Views: 1440

Answers (2)

Bhas
Bhas

Reputation: 1834

You can only use the gfortran version that was used to build R. Since you are on Lion and presumably have Xcode installed you can get the appropriate version of gfortran from here: http://r.research.att.com/tools/ Go to section: "Apple Xcode gcc-42 add-ons" and choose the appropriate version.

You'll have to get rid of your gfortran 4.6.2 completely or make it inaccessible by changing PATH if possible (which I doubt unless it is in /opt/...).

And do use R CMD SHLIB since that will pass the correct options to compiler and linker.

Upvotes: 2

themel
themel

Reputation: 8895

Unless you really understand what you're doing, you should use gfortran that comes with R tools. The missing symbol in libgcc isn't surprising since you're trying to run code compiled with a 4.6 gfortran in a 4.2 runtime environment.

Upvotes: 3

Related Questions