[R] Problems with a dll under windows

Duncan Murdoch dmurdoch at pair.com
Mon Jul 7 12:53:28 CEST 2003

On Mon, 07 Jul 2003 13:49:01 +1000, you wrote:

>//silly function to test returning a constant double
>void X::Give7(double * a)   
>    *a=7;
>---- end rtest.cpp
>Then I create the dll using the following DOS command
>   Rcmd SHLIB rtest.cpp
>(I have all the perl, MINGW and related stuff set up as
>per the instructions at http://www.stats.ox.ac.uk/pub/Rtools/)
>Then in R, I type the following.
>> x <- 3
>> dyn.load("rtest.dll")
>So far, so good.
>Then...PROBLEM 1
>> .C("Give7",x)
>Error in .C("Give7", x) : C/Fortran function name not in load table

A call to Give7 needs to pass both an instance of X and a.  You're
only passing a, because R doesn't know anything about instances of X.

Generally speaking, R can only call standard C functions, not C++
methods.  Your example seems to be based on the Writing R Extensions
section 4.6 example, but you miss the last part of it:  R can only
call X_main, not X::Give7.

Duncan Murdoch
>How do you convince the compiler to use the name "Give7" as an entry
>And PROBLEM 2...
>I checked the DLL and the names have been decorated.
>If I use the decorated name I get the following:
>> .C("_ZN1X5Give7EPd",x)
>[1] 3
>For some reason, it is not altering x as it should.
>What am I doing wrong?
>Rob Hyndman
>Rob J Hyndman
>Associate Professor & Director of Consulting
>Department of Econometrics & Business Statistics
>Monash University, VIC 3800, Australia.
>R-help at stat.math.ethz.ch mailing list

More information about the R-help mailing list