[Rcpp-devel] Got error when trying to run example in Intro vignette
Douglas Bates
bates at stat.wisc.edu
Tue Dec 21 18:31:34 CET 2010
On Tue, Dec 21, 2010 at 11:21 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> I tried copying the example in the intro vignette
> http://dirk.eddelbuettel.com/code/rcpp/Rcpp-introduction.pdf
> and get the following error. What's wrong?
Hmm. The externally-callable function is being declared twice,
perhaps due to a change in the syntax of the "body" part of
cxxfunction.
Just delete the first and last lines of the body string. That is
start with Rcpp::NumericVector ... and end with "return xab;"
>> library(inline)
>> library(Rcpp)
>> funIntro <- cxxfunction(signature(a = "numeric", b = "numeric"), body = '
> + RcppExport SEXP convolve3cpp(SEXP a, SEXP b) {
> + Rcpp::NumericVector xa(a);
> + Rcpp::NumericVector xb(b);
> + int n_xa = xa.size(), n_xb = xb.size();
> + int nab = n_xa + n_xb - 1;
> + Rcpp::NumericVector xab(nab);
> + for (int i = 0; i < n_xa; i++)
> + for (int j = 0; j < n_xb; j++)
> + xab[i + j] += xa[i] * xb[j];
> + return xab;
> + }', plugin="Rcpp")
> file303dbfd.cpp: In function 'SEXPREC* file303dbfd(SEXPREC*, SEXPREC*)':
> file303dbfd.cpp:31:1: error: expected unqualified-id before string constant
> make: *** [file303dbfd.o] Error 1
>
> ERROR(s) during compilation: source code errors or compiler
> configuration errors!
>
> Program source:
> 1:
> 2: // includes from the plugin
> 3:
> 4: #include <Rcpp.h>
> 5:
> 6:
> 7: #ifndef BEGIN_RCPP
> 8: #define BEGIN_RCPP
> 9: #endif
> 10:
> 11: #ifndef END_RCPP
> 12: #define END_RCPP
> 13: #endif
> 14:
> 15: using namespace Rcpp;
> 16:
> 17:
> 18: // user includes
> 19:
> 20:
> 21: // declarations
> 22: extern "C" {
> 23: SEXP file303dbfd( SEXP a, SEXP b) ;
> 24: }
> 25:
> 26: // definition
> 27:
> 28: SEXP file303dbfd( SEXP a, SEXP b ){
> 29: BEGIN_RCPP
> 30:
> 31: RcppExport SEXP convolve3cpp(SEXP a, SEXP b) {
> 32: Rcpp::NumericVector xa(a);
> 33: Rcpp::NumericVector xb(b);
> 34: int n_xa = xa.size(), n_xb = xb.size();
> 35: int nab = n_xa + n_xb - 1;
> 36: Rcpp::NumericVector xab(nab);
> 37: for (int i = 0; i < n_xa; i++)
> 38: for (int j = 0; j < n_xb; j++)
> 39: xab[i + j] += xa[i] * xb[j];
> 40: return xab;
> 41: }
> 42: END_RCPP
> 43: }
> 44:
> 45:
> Error in compileCode(f, code, language = language, verbose = verbose) :
> Compilation ERROR, function(s)/method(s) not created!
> file303dbfd.cpp: In function 'SEXPREC* file303dbfd(SEXPREC*,
> SEXPREC*)':
> file303dbfd.cpp:31:1: error: expected unqualified-id before string constant
> make: *** [file303dbfd.o] Error 1
> In addition: Warning message:
> running command 'C:\PROGRA~1\R\R-212~1.X/bin/i386/R CMD SHLIB
> file303dbfd.cpp 2> file303dbfd.cpp.err.txt' had status 1
>>
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
> _______________________________________________
> 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
>
More information about the Rcpp-devel
mailing list