[Rd] pb with dyn.load - fortran code now attached

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Oct 26 17:32:17 CEST 2005


On Wed, 26 Oct 2005, Paul Roebuck wrote:

> On Wed, 26 Oct 2005, Gilles GUILLOT wrote:
>
>> QUESTION 1:
>> [guillot at laplace guillot]$ R
>> R : Copyright 2005, The R Foundation for Statistical Computing
>> Version 2.2.0  (2005-10-06 r35749)
>> ISBN 3-900051-07-0
>>
>> >system("R CMD SHLIB ~/tmp/test1.f")
>> g77   -fPIC  -g -O2 -c /home/guillot/tmp/test1.f -o /home/guillot/tmp/test1.o
>> gcc -shared -L/usr/local/lib
>> -o /home/guillot/tmp/test1.so /home/guillot/tmp/test1.o  -lg2c -lm -lgcc_s
>>> system("R CMD SHLIB ~/tmp/test2.f")
>> g77   -fPIC  -g -O2 -c /home/guillot/tmp/test2.f -o /home/guillot/tmp/test2.o
>> gcc -shared -L/usr/local/lib
>> -o /home/guillot/tmp/test2.so /home/guillot/tmp/test2.o  -lg2c -lm -lgcc_s
>>>
>>> is.loaded("sub")
>> [1] FALSE
>>> is.loaded("sub_")
>> [1] FALSE
>>>
>> ## OK
>>> dyn.load("~/tmp/test1.so")
>>> is.loaded("sub")
>> [1] FALSE
>>> is.loaded("sub_")
>> [1] TRUE
>>>
>> ## it seems it does not comply with the 'value' section of the help
>> ## of function is.loaded:
>> ## "it needs the
>> ##    name you would give to '.C' or '.Fortran' and *not* that remapped
>> ##    by 'symbol.C' and 'symbol.For'."
>> ##
>> ## am i missing something ?
>>> q()
>
> The is.loaded method needs the argument to look exactly
> like the associated output from 'nm' (i.e., symbol name).
>
> $ nm ~/tmp/test1.so | grep sub
>
> Thus, you are manually asking for the following
>
>> is.loaded(symbol.For("sub"))
>
> The call to .Fortran use the (lowercase) name of the subroutine
> as it would appear in the Fortran source code.
>
> .Fortran("sub", ...)

Not at all the whole story.  First (unfortunately), the case mapping is 
OS-dependent and even compiler-dependent.  Second, look at stats.so which 
has

00030cf0 T supsmu_

yet

> is.loaded("supsmu_")
[1] FALSE
> is.loaded("supsmu")
[1] TRUE

That is a Fortran entry point, and it complies with the description 
quoted.

What is.loaded() needs depends on how the symbol would be found 
and so it is not much use.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list