[Rcpp-devel] Local .h files and Rcpp attributes

Mark Fredrickson mark.m.fredrickson at gmail.com
Sat Oct 19 16:41:49 CEST 2013


>
> The same trick was already used in RcppDE (which was a proof of concept
> about
> converting DEoption from 700 lines of plain C to 400 lines of C++ / Rcpp)
> where I have
>
>         typedef double (*funcPtr)(SEXP);
>
> and the rest works like a 'plain old package'.
>

Certainly. And while I haven't implemented the switching between C++ and R
functions, when I use `sourceCpp` to compile and load the file, everything
seems to work.


>
> | My (perhaps naive) attempts are giving errors about my `funcPtr` type
> not being
> | defined. I've tried moving this definition to a header file, but even
> with `//
> | [[Rcpp::depends(myheader)]]` or `\\[Rcpp::depends(myheader.h)]]`, the
> generated
> | RcppExports.cpp file does not include `myheader.h`.
>
> What exactly is the error?



Error:

make[1]: Entering directory
`/tmp/RtmpTfIlij/R.INSTALL4a2441f79c5/RItools/src'
g++ -I/usr/include/R/ -DNDEBUG  -D_FORTIFY_SOURCE=2
-I"/home/mark/Documents/Software/RItools/.local/Rcpp/include"   -fpic
-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector
--param=ssp-buffer-size=4  -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:59:6: error: ‘testStat’ was not declared in this scope
 XPtr<testStat> testStatisticPtr(std::string f);



>  Could it be as simple as missing
>
>      -I.
>
> in src/Makevars ?  That is not added by default so try adding the line
>
>     PKG_CPPFLAGS = -I.
>
> (not indented, of course) to src/Makevars (and src/Makevars.win)
>

Thanks for the suggestion, though it does not resolve the above issue. The
generated RcppExports.cpp:

// This file was generated by Rcpp::compileAttributes
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#include <Rcpp.h>

...

// testStatisticPtr
XPtr<testStat> testStatisticPtr(std::string f);
RcppExport SEXP RItools_testStatisticPtr(SEXP fSEXP) {
BEGIN_RCPP
    SEXP __sexp_result;
    {
        Rcpp::RNGScope __rngScope;
        Rcpp::traits::input_parameter< std::string >::type f(fSEXP );
        XPtr<testStat> __result = testStatisticPtr(f);
        PROTECT(__sexp_result = Rcpp::wrap(__result));
    }
    UNPROTECT(1);
    return __sexp_result;
END_RCPP
}

---

The issue being that my local teststatistics.h is not included, so the
typedef is not visible when compiling this file.

I suspect the solution is just to write the export wrapper for this
particular function manually (I could just copy and paste). That way
RcppExports.cpp never has to deal with the typedef.

Thanks for help,
-Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20131019/b1907513/attachment.html>


More information about the Rcpp-devel mailing list