[R] interfacing C++ using .Call

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Tue Feb 17 18:46:45 CET 2004



Thomas Lumley wrote:

> On Tue, 17 Feb 2004, Sundar Dorai-Raj wrote:
> 
> 
>>Hi folks,
>>   I apologise if this is in the documentation somewhere, but I can't
>>seem to find it. I also did a search of CRAN without any success. I'm
>>using R-1.8.1 (pre-compiled) on Windows 2000 with Rtools and mingw 2.0.0
>>(which includes gcc/g++ 3.2).
>>
>>I'm trying to link some C++ code from another application to R using the
>>.Call interface and am experiencing some problems. I was able to compile
>>and link the example from Section 4.6 in R-exts.pdf without any
>>difficulty. But if I take a more complicated example that uses SEXP I'm
>>able to compile but not link. Here's an example:
>>
> 
> <snip>
> 
>>Adding extern "C" {} does not help the problem. Can anybody replicate
>>this? Is there something I'm missing?
> 
> 
> Did you put extern "C" {} around the #include as well?  

No I did not. That fixed it.

Thanks for the speedy reply.

Regards,
Sundar


Using
> R/doc/manual/R-exts.c and the driver in R/doc/manual/R-exts.R
> I don't have any problems if I rename R-exts.c to R-exts.cpp as long as
> the extern "C" {} surrounds the headers as well as the code.
> 
> In my case (on OS X) the error when I don't do this comes at load time
> rather than compile time, and it's clear that the problem is C++ name
> mangling
> 
> Error in dyn.load(x, as.logical(local), as.logical(now)) :
>         unable to load shared library "/Users/thomas/R-exts.so":
>   dlcompat: dyld: /usr/local/lib/R/bin/R.bin Undefined symbols:
> __Z10Rf_findVarP7SEXPRECS0_
> __Z10Rf_installPKc
> __Z10Rf_protectP7SEXPREC
> __Z10STRING_ELTP7SEXPRECi
> __Z10VECTOR_ELTP7SEXPRECi
> __Z11Rf_isStringP7SEXPREC
> __Z12Rf_defineVarP7SEXPRECS0_S0_
> __Z12Rf_ge
> 
> 
> An unusual example of it being easier to debug a shared library problem
> under Mac OS X ;)
> 
> 
> 	-thomas




More information about the R-help mailing list