On Tue, Feb 23, 1999 at 09:45:21PM +0100, james.pigott at ucd.ie
wrote:> I'm using Borland C++ for windows version 4.51 to export functions
> in a dll to R but i've encountered the following problems
> -- R crashes when function has more than one parameter
> -- Array subscripts in C++ code access wrong elements
> -- dll is not portable to different computer .i.e R (dyn.load) will only
> call the dll on the the machine the dll was compiled o
Both B. Ripley and I are
making available DLL's which don't seem to suffer of your
first and third problem. However, none of these, if
I remember, has C++ code.
Crashes are easy to obtain if you don't respect exactly
the ".C calling convention", e.g., if your function think
to receive a string and not a vector of strings. This
could also explain second problem. But it is just an
hypothesis. If you want, try to reduce at the minimum
your source (at the level of a small toy) then post it.
>
> Does the dll need to be compiled on a particular version of C ??
In theory no. I have used dll's compiled with Visual C++ without
problems. And I received some reports that lcc works well.
However, most of the people are using the GNU copyleft
egcs compiler. Surely, binaries at CRAN are made using
egcs.
>
> I would appreciate the solution to these problem(s) and/or perhaps
> an example of some C code.
A basic example of dynamic loading (including call_[R,S]) is
in the demo/dynload directory of the source. Observe that
the C dll calls routines in the main code which under
Windows is in R.dll. Hence, you need to link against
R.dll (how depends upon the compiler, you have to
generate an appropriate import library from the R.dll,
on this point, not specific to R but including examples of use of many
different compilers, you can give a look to the Luke Tierney's
http://stat.umn.edu/~luke/xls/projects/dlbasics/dlbasics.html
guido
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._