David Stevens
2012-Jan-15 22:34 UTC
[R] Calling Fortran from R: Issues with dynamic loading of fortran dll
I successfully used .Fortran to load and execute my fortran procedures under WinXP and 32 bit R. Alas, the same isn't true with my next Windows 7/64 machine, R 2.14.1 (64 bit) and the gnu gfortran (64) compiler (mingw64 v. 4.6.1). Though I'm able to compile the routines from the command line using gfortran '...', .Fortran('foo2') results in an error saying the Fortran symbol name "foo2" not in load table. foo.f90: Module foo contains Subroutine foo2(x) real(kind=8),intent(inout) :: x x = x + 2 end subroutine foo2 end module foo c:\mingw64\bin\gfortran --shared -Wall -pedantic -g -o foo.dll foo.f90 ff = "d:/Fortran folders/Fortran Multiresponse/foo.dll" x= dyn.load(ff) .Fortran('foo2',as.double(1)) Error in .Fortran("foo", as.double(1)) : Fortran symbol name "foo" not in load table Can someone point me in the direction of a solution? Regards David -- David K Stevens, P.E., Ph.D., Professor Civil and Environmental Engineering Utah Water Research Laboratory 8200 Old Main Hill Logan, UT 84322-8200 435 797 3229 - voice 435 797 1363 - fax david.stevens@usu.edu [[alternative HTML version deleted]]
Duncan Murdoch
2012-Jan-16 00:09 UTC
[R] Calling Fortran from R: Issues with dynamic loading of fortran dll
On 12-01-15 5:34 PM, David Stevens wrote:> I successfully used .Fortran to load and execute my fortran procedures > under WinXP and 32 bit R. Alas, the same isn't true with my next Windows > 7/64 machine, R 2.14.1 (64 bit) and the gnu gfortran (64) compiler > (mingw64 v. 4.6.1). Though I'm able to compile the routines from the > command line using gfortran '...', .Fortran('foo2') results in an error > saying the Fortran symbol name "foo2" not in load table. > > foo.f90: > > Module foo > contains > Subroutine foo2(x) > > real(kind=8),intent(inout) :: x > x = x + 2 > > end subroutine foo2 > > end module foo > > c:\mingw64\bin\gfortran --shared -Wall -pedantic -g -o foo.dll foo.f90 > > ff = "d:/Fortran folders/Fortran Multiresponse/foo.dll" > x= dyn.load(ff) > .Fortran('foo2',as.double(1)) > > Error in .Fortran("foo", as.double(1)) : > Fortran symbol name "foo" not in load table > > Can someone point me in the direction of a solution?Some or all of these might help: 1. Get R to do the compiling for you: it knows the compiler arguments that produce compatible code. (Use R CMD shlib for this.) 2. Use a compiler supplied with the Rtools collection. 3. Find out what name got exported, and use .C instead of .Fortran to call that. Duncan Murdoch