[R] Problems with a dll under windows

Rob Hyndman rob.hyndman at buseco.monash.edu.au
Mon Jul 7 05:49:01 CEST 2003


I am trying to get a dll compiled for use with dyn.load. I use R.1.7.1
under Windows.

I have tried the following trivial example based on the "Writing R
extensions" manual.

rtest.h
--------
class X {
public:
    X ();
    ~X ();
    void Give7(double*);
};

class Y {
public: Y (); ~Y ();
};

rtest.cpp
---------
#include <iostream.h>
#include "rtest.h"

static Y y;


extern "C" {

    void X_main () {
            X x;
    }
}

X::X()   { std::cout << "construct X" << std::endl; }
X::~X()  { std::cout << "destruct X"  << std::endl; }
Y::Y()   { std::cout << "construct Y" << std::endl; }
Y::~Y()  { std::cout << "destruct Y"  << std::endl; }

//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

How do you convince the compiler to use the name "Give7" as an entry
point?

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]]
[1] 3

For some reason, it is not altering x as it should.

What am I doing wrong?

Thanks.
Rob Hyndman
___________________________________________________
Rob J Hyndman
Associate Professor & Director of Consulting
Department of Econometrics & Business Statistics
Monash University, VIC 3800, Australia.
http://www-personal.buseco.monash.edu.au/~hyndman/




More information about the R-help mailing list