Reputation: 861
Well, I recently fell in love with Fortran
(f90
) and have been trying to understand the "kung-fu" of R
and Fortran
. I found several relevant and helpful questions here (e.g. this and this).
What I am trying to do:
I am (probably, trying to do something crazy) trying to call the following .f90
subroutines in R
(x64) using .Fortran()
function. Here is the test.f90
code:
! Computes the square of a number
Subroutine sr1(a,b)
!DEC$ ATTRIBUTES DLLEXPORT::sr1
!DEC$ ATTRIBUTES C, REFERENCE, ALIAS:'sr1' :: sr1
implicit none
integer a,b
b = a*a
End Subroutine sr1
! Computes the cube of a number
Subroutine sr2(x,y)
!DEC$ ATTRIBUTES DLLEXPORT::sr2
!DEC$ ATTRIBUTES C, REFERENCE, ALIAS:'sr2' :: sr2
implicit none
integer x,y
y = x*x*x
End Subroutine sr2
I am compiling the above test.f90
code via gfortran
on my Windows 10 machine by:
gfortran -shared -o test.dll test.f90
The compilation works and I get the test.dll
. Now, in R
. I try to load it:
dyn.load("path_to_file/test.dll")
It works. But, it fails here:
> is.loaded("test")
[1] False
I already found a relevant question here. But, I could not get the clue to fix my problem. Can someone suggest some workaround to fix the issue?
Upvotes: 1
Views: 358
Reputation: 60008
I am not a big user of R, but my tests show that while
is.loaded("test_R")
indeed returns FALSE
, both
is.loaded("sr1")
and
is.loaded("sr2")
return TRUE
. But I did my tests on Linux and GCC which may interpret the extrnally visible subroutine names differently.
Upvotes: 1