Could it be because the file extension is .c rather than the expected .cpp? Compiling the code runs fine for me when the file extension is .cpp, but I get the same errors as you with the file extension as .c .
-Kevin On Wed, Feb 13, 2013 at 11:15 PM, Bharath Govindarajan < bharath.qu...@gmail.com> wrote: > Hi, > > At the outset I would like to thank the developers of rcpp for this > wonderful tool. My question > is elementary but I am posting it here only because on stack exchange I > see Dirk suggesting that > this is a better place to get replies. > > Thanks again > Bharath > > > > Places I searched so far : > ------------------------------------- > google , stack exchange : > " rcpp compilation error __attribute__ " > " rcpp Reference.h:25 error" > " rcpp asm error" > > > > > version > _ > platform x86_64-unknown-linux-gnu > arch x86_64 > os linux-gnu > system x86_64, linux-gnu > status > major 2 > minor 15.1 > year 2012 > month 06 > day 22 > svn rev 59600 > language R > version.string R version 2.15.1 (2012-06-22) > nickname Roasted Marshmallows > > Description of problem: > -------------------------------- > I tried a very simple example from Hadley Wickham's website and it worked > https://github.com/hadley/devtools/wiki/Rcpp > > cppFunction(' > double sumC(NumericVector x) { > int n = x.size(); > double total = 0; > for(int i = 0; i < n; ++i) { > total += x[i]; > } > return total; > } > ') > > Then I try an example written in a c source file from > http://dirk.eddelbuettel.com/blog/2012/11/14/ > and source it and get compilation errors > > test1.c > ------ > #include <Rcpp.h> > > // [[Rcpp::export]] > Rcpp::DataFrame mypnorm(Rcpp::NumericVector x) { > int n = x.size(); > Rcpp::NumericVector y1(n), y2(n), y3(n); > > for (int i=0; i<n; i++) { > > // the way we used to do this > y1[i] = ::Rf_pnorm5(x[i], 0.0, 1.0, 1, 0); > > // the way we can do it now > y2[i] = R::pnorm(x[i], 0.0, 1.0, 1, 0); > > } > // or using Rcpp sugar in one go > y3 = Rcpp::pnorm(x); > > return Rcpp::DataFrame::create(Rcpp::Named("Rold") = y1, > Rcpp::Named("Rnew") = y2, > Rcpp::Named("sugar") = y3); > } > > commands: > --------- > sourceCpp(LIB.PATH %+% "test1.c",verbose=TRUE) > > Error: > ------ > > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/internal/wrap_end.h:25: > error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Rcpp' > In file included from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/meat.h:25, > from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp.h:81, > from test1.c:1: > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/RObject.h:25: > error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Rcpp' > In file included from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/meat.h:26, > from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp.h:81, > from test1.c:1: > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/Environment.h:25: > error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Rcpp' > In file included from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/meat.h:27, > from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp.h:81, > from test1.c:1: > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/DottedPair.h:25: > error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Rcpp' > In file included from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/meat.h:28, > from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp.h:81, > from test1.c:1: > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/Vector.h:25: > error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Rcpp' > In file included from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/meat.h:29, > from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp.h:81, > from test1.c:1: > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/Matrix.h:25: > error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Rcpp' > In file included from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/meat.h:30, > from > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp.h:81, > from test1.c:1: > R/x86_64-unknown-linux-gnu-library/2.15/Rcpp/include/Rcpp/api/meat/Reference.h:25: > error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Rcpp' > test1.c:4: error: expected '=', ',', ';', 'asm' or '__attribute__' before > ':' token > test1.c:28: error: expected identifier or '(' before string constant > make: *** [test1.o] Error 1 > Error in sourceCpp(LIB.PATH %+% "test1.c", verbose = TRUE) : > Error 1 occurred building shared library. > > > > _______________________________________________ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel >
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel