[Rcpp-devel] error: expected unqualified-id before string constant

Dirk Eddelbuettel edd at debian.org
Sun Feb 24 16:26:09 CET 2013


On 24 February 2013 at 09:56, Greg Minshall wrote:
| hi.  another "find" in experimenting is that [[Rcpp::export]] and the
| RcppExport (in, e.g.,
| ----
| // [[Rcpp::export]]
| RcppExport SEXP pass1(Rcpp::IntegerVector rgbtotype,
|                       Rcpp::IntegerMatrix pixmap,
|                       int toosmall) {...}
| ----
| are mutually exclusive.  that's probably a "duh!", but it kept me
| blissfully confused for an entertaining hour or four.  here is the
| longer version of the error message when compiling:
| ----
| > sourceCpp("cluster.cc")
| cluster.cc: In function 'SEXPREC* sourceCpp_54257_pass1(SEXPREC*, SEXPREC*, SEXPREC*)':
| cluster.cc:438: error: expected unqualified-id before string constant
| cluster.cc:439: error: '__result' was not declared in this scope
| make: *** [cluster.o] Error 1
| ----
| 
| (just to be clear: you can have either one, or the other, but not both.)
| 
| (i suppose [[Rcpp::export]] *could* redefine RcppExport to NULL, which
| might help the unwary.)

Ouch indeed.  

That is what we get for providing multiple ways to skin the cat. :-/

I presume that the Rcpp-attributes vignette never ever shows RcppExport, and
JJ probably did not assume it could be used.  

And it "really" is just an alias for the uglier-looking 'extern "C"'.  And of
course added by the very layers that sourceCpp() puts around the code you
give it... so you are pretty much expected not to put it there.  Does using
verbose=TRUE help / give any hints?

In my mind, the way to think about this is that sourceCpp() will compile and
link the __C++ interface__ functions you give and provice __.Call() interfaces__
by building wrappers.  You stuck something for the latter onto the former,
things broke and you got to keep the pieces.

Dirk

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


More information about the Rcpp-devel mailing list