[Rcpp-devel] #ifdef'd out // [[Rcpp::export]]

JJ Allaire jj.allaire at gmail.com
Sun Feb 24 18:23:48 CET 2013


Hi Greg,

While sourceCpp does parsing of the translation unit to discover exported
functions, it's not a full-on C++ parser (that would require a huge effort
and/or taking on a large dependency like libclang or gccxml). In any case,
in our parser we try to be as semantically sophisticated as we can but as
you discovered we don't get everything. For your case, we do however
respect block-level comments so you could temporarily exclude a part of the
translation unit using /* */.

J.J.

On Sun, Feb 24, 2013 at 11:35 AM, Greg Minshall <minshall at umich.edu> wrote:

> hi.  first, i should mention that i think Rcpp is amazing!  i'm enjoying
> the learning process, and it speeds up my formerly-R code greatly.
> (some trivial image processing thing that i was only doing in R in order
> to combine two learning activities into one.)
>
> but... ;-)
>
> if i sourceCpp() the following code:
> ----
> #include <Rcpp.h>
>
> #if 0
> // [[Rcpp::export]]
> int foo() {
>     return 3;
> }
> #endif /* 0 */
> ----
> i get this set of error messages
> ----
> > sourceCpp("foo.cc")
> foo.cc: In function 'SEXPREC* sourceCpp_15583_foo()':
> foo.cc:16: error: 'foo' was not declared in this scope
> make: *** [foo.o] Error 1
> flag-sort -r g++
> -I/sw/Library/Frameworks/R.framework/Versions/2.15/Resources/include
> -DNDEBUG  -I/sw/include
>  -I"/Users/minshall/Library/R/2.15/library/Rcpp/include"   -fPIC  -g -O2
>  -c foo.cc -o foo.o
> Error in sourceCpp("foo.cc") : Error 1 occurred building shared library.
> ----
>
> btw, thanks for pointing me at "verbose=TRUE" in sourceCpp().  i was
> wondering how to get something like "g++ -E".  (and, it shows me what's
> going on under the hood in this case.)
>
> cheers!
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130224/9bb16f19/attachment.html>


More information about the Rcpp-devel mailing list