[R] [r] Problems with Fortran calls when loaded a dll compiled with gfortran-4 Cygwin 4.5.3
Duncan Murdoch
murdoch.duncan at gmail.com
Wed Apr 24 20:08:52 CEST 2013
On 13-04-24 1:51 PM, Jens Olofsson wrote:
> Dear Duncan,
> I know this isn't a forum for Cygwin, but for R. Pls treat me as a noob and
> also remember I am on Windows. How should I use R CMD SHLIB as if I write
> that at the prompt I get the error: unexpected symbol in "R CMD". I have
> mango.f95 in the working directory.
That's a command-line command, not something done with R. You can use
it from your bash shell if you have R and the Rtools directories on your
path, or from the Windows CMD shell.
BTW, my comment wasn't trying to tell you to go to a Cygwin forum, it
was telling you that Cygwin's gfortran is unsupported. You need to use
the MinGW-64 one that we distribute if you want us to be able to help.
Duncan Murdoch
> //Jens
>
>
>
> On 24 April 2013 19:46, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>
>> On 13-04-24 1:36 PM, Jens Olofsson wrote:
>>
>>> Dear users of R
>>> I have a subroutine in Fortran95, compiled to a DLL with gfortran in
>>> Cygwin
>>> 4.5.3.
>>>
>>
>> We don't support Cygwin. You should use the gfortran in Rtools, and get R
>> to set the command line options for you, either by putting the code in a
>> package, or by using R CMD SHLIB Mango.f95.
>>
>> Duncan Murdoch
>>
>> The subroutine is:
>>> subroutine MyPBP( S, p, N )
>>> ! Expose subroutine rtest to users of this DLL
>>> !DEC$ ATTRIBUTES DLLEXPORT, C, REFERENCE, ALIAS: "mypbp_" ::mypbp
>>> ! This function computes the Poisson-Binomial distribution
>>> ! of size N using p
>>> double precision, intent(inout) :: S(N+1)
>>> double precision, intent(in) :: p(N)
>>> integer, intent(in) :: N
>>> double precision :: X(N+1)
>>> integer i, j
>>> !X=0
>>> !S=0
>>> X(1) = 1 - p(1)
>>> X(2) = p(1)
>>> do i = 2, N
>>> S(1) = X(1)*(1-p(i))
>>> do j = 2,i
>>> S(j) = X(j-1)*p(i) + X(j)*(1-p(i))
>>> end do
>>> S(i+1) = X(i)*p(i)
>>> X = S
>>> if (i == N) then
>>> S = X
>>> end if
>>> end do
>>> end subroutine MyPBP
>>> and it is saved into Mango.f95
>>> I compile it from the bash shell using: gfortran-4 c- Mango.f95 and
>>> gfortran-4 -shared -o Mango.dll Mango.o
>>> I am on a Windows machine running Windows 7 with Intel i7.
>>> I load the dll in a 32-bit R by dyn.load("Mango.dll"). Using getLoadedDLLs
>>> I can see the DLL. However, is.loaded("Mango.dll") = FALSE. In addition, R
>>> stop responding when I try .Fortran("MyPBP", as.numeric(S), as.numeric(p),
>>> as.integer(N)),
>>> where N<-5, S<-array(0,N+1) and p<- c(0.1, 0.2, 0.5, 0.8, 0.9).
>>>
>>> What am I doing wrong?
>>> Any ideas, thoughts and/or comments are highly appreciated.
>>>
>>> Jens
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________**________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>
More information about the R-help
mailing list