[Rcpp-devel] Ripping C source from R

Dirk Eddelbuettel edd at debian.org
Mon Jul 2 13:03:16 CEST 2012


On 2 July 2012 at 04:40, Silkworth,David J. wrote:
| I am attempting to take a copy of the entire splines.c file and use this for
| compilation into a new project (so I can call spline_basis() directly, but
| preserve the identity and integrity of the original work.
|  
| When I tried to pack this code into the include for the inline cxxfunction call
| I ended up with compile errors like:
|  
| file81b983.cpp: In function 'SEXPREC* spline_basis(SEXPREC*, SEXPREC*,
| SEXPREC*, SEXPREC*)':
| file81b983.cpp:143:1: error: 'coerceVector' was not declared in this scope
| file81b983.cpp:144:35: error: 'length' was not declared in this scope
| file81b983.cpp:156:1: error: 'allocMatrix' was not declared in this scope
| file81b983.cpp:157:1: error: 'allocVector' was not declared in this scope
| file81b983.cpp:179:33: error: 'install' was not declared in this scope
| file81b983.cpp:179:43: error: 'setAttrib' was not declared in this scope
|  
| These errors pertain to lines like:
| PROTECT(knots = coerceVector(knots, REALSXP));
| PROTECT(val = allocMatrix(REALSXP, sp->order, nx));
|  
| I tried a similar action on the famous convolve2 code from ?Writing R
| Extensions? with very similar result.
| ( I also tried adding the pre-pended directive ?extern ?C? ?to the function
| declaration.)
|  
| I am pretty sure that the problem has to do with compiling C code using a C++
| compiler, but I thought I  might get away with it.
|  
| Does this prompt any thoughts, or should I just give up on this path.

See Section 6 "The R API: entry points for C code" about

     This remapping can cause problems(1), and can be eliminated by
  defining `R_NO_REMAP' and prepending `Rf_' to _all_ the function names
  used from `Rinternals.h' and `R_ext/Error.h'.

so you either need to undefine 'R_NO_REMAP' for the code segment you
'ripped', or else simply pre-pend 'Rf_' to all identifiers.  

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list