[R] [r] Problems with Fortran calls when loaded a dll compiled with gfortran-4 Cygwin 4.5.3

Jens Olofsson jens.olofsson at gmail.com
Wed Apr 24 21:57:55 CEST 2013


Hello again. 

I may be a bit slow, but I'm learning. :-)
Installed Rtools, added R to the path. Used CMD, moved to the folder of the source and wrote R CMD SHLIB Mango.f95 and voila I got a dll I loaded in R and I could call my current subroutines as intended. 

I am very grateful for ur help and ur patience. 

Sincerely, Jens

24 apr 2013 kl. 21:33 skrev "R. Michael Weylandt <michael.weylandt at gmail.com>" <michael.weylandt at gmail.com>:

> 
> 
> On Apr 24, 2013, at 7:46 PM, Jens Olofsson <jens.olofsson at gmail.com> wrote:
> 
>> Ok. I apologise for not understanding. So, I have installed R-tools. It
>> changed my PATH-variable. I didn't installed Cygwin dlls as stated by
>> http://cran.r-project.org/doc/manuals/R-admin.html#The-Windows-toolset.
>> Instead my PATH-variable contains the path to the Cygwin dlls AFTER the
>> path to R... So, I started RTerm (32-bit) and tried > R CMD SHLIB mango.f95
> 
> Repeating what Duncan said -- R CMD SHLIB is to be done outside of R, not within R. 
> 
> Some recent discussion also suggests its perhaps easier to do this with RStudio + devtools as part of a package than as a standalone shared object. 
> 
> MW
> 
> 
>> and got the same error as earlier "Error: unexpected symbol in "R CMD"".
>> The same goes for RTerm (64-bit). Can you pls advice me on how to proceed?
>> Sincerely Jens
>> 
>> 
>> On 24 April 2013 20:08, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>> 
>>> 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>
>>>>>> <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<http://www.R-project.org/posting-guide.html>
>>>>>> 
>>>>>> and provide commented, minimal, self-contained, reproducible code.
>> 
>>   [[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list