[R] problems linking c++ code
Allan Strand
stranda at cofc.edu
Mon Sep 10 13:33:47 CEST 2001
Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
> On 9 Sep 2001, Allan Strand wrote:
>
> >
> > I've been trying to learn about dynamically loading subroutines in R.
> > Ultimately I would like to use this approach to implement some
> > simulations. For the moment though, I've run into a problem compiling
> > c++ code and loading it into R.
> >
> > The 'C/C++' and 'R'code below works fine when compiled and linked with
> > gcc, but gives an error when the library is compiled and linked with
> > g++. In the case when it fails, it does so because of an undefined
> > symbol in the *.so file. Is there something I can link in to resolve
> > this problem? Is there another obvious solution?
>
> Using the Rinternals.h in C++ code is not supported.
> It's not clear to me why you are writing C in C++ inside extern "C"
> declarations, but if you do you need to put
> the Rinternals.h inside extern "C" too.
That certainly fixes the problem I posted.
I had c++ code inside the extern "C" {} as well. The simulation
library I have already written is in c++. I tried to pare down the
code to the smallest functioning bit that still exhibited the
behavior. I didn't want to post a more extraneous code than
necessary. Ultimately, I'd like to instantiate a c++ object and
convert it into several R objects.
>
> BTW, you code is not using Rdefines.h, but I think that may need to be
It was using Rdefines.h, but I went to the Rinternals solution while
exploring my problem.
> inside extern "C" too.
>
> The `standard' headers (those used with .C) have extern "C" wrappers, but
> not the advanced ones for .Call/.Extern. We assume that people using
> .Call are pretty au fait with their ccompiler systems, and already know
> how to use .C.
>
Clumsily trying to develop such an expertise...
Do you know of examples of c++ code interfaced through the
.Call/.Extern system?
Thanks for your pointers,
a.
--
Allan Strand, Biology http://linum.cofc.edu
College of Charleston Ph. (843) 953-8085
Charleston, SC 29424 Fax (843) 953-5453
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list