Question

I have a cpp file which I am trying to compile with sourceCpp() from RStudio. It includes Rcpp.h, all the necessary STL stuff and "using namespace Rcpp;".

Then it has several function declarations (not exported to R), the function that should be exported to R, and finally the definitions of the declared functions.

This is what I get when I try to compile:

g++ -m32 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG     -I"C:/Users/Michelle/Documents/R/win-library/3.0/Rcpp/include"  -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c RW_FastSwap.cpp -o RW_FastSwap.o

RW_FastSwap.cpp: In function 'SEXPREC* sourceCpp_27691_fastswap(SEXP, SEXP, SEXP, SEXP, SEXP)':

RW_FastSwap.cpp:459:9: error: '__result' was not declared in this scope

make: *** [RW_FastSwap.o] Error 1


Error in Rcpp::sourceCpp("C:/Users/Michelle/Desktop/Google Drive/FastSwap/RW_FastSwap.cpp") : 
  Error 1 occurred building shared library.

That line number is 15 lines more than the last line of the cpp file, i.e. the last line of the cpp file is 444. I've made sure that the type of the result returned from the exported function matches the return type of the function.

Any guidance on fixing this will be greatly appreciated.

No correct solution

OTHER TIPS

We may need to see the code, or a mocked up version.

When you use the compileAttributes() function to compile an Rcpp function---be it by pressing the button in RStudio, or explicitly---it creates additonal code around your code sample (essentially dealing with data conversion etc).

I think I may have seen that error when I did something silly like not including a correct return statement.

Edit based on Ian's comment: This works for me (with manual line break here for SO)

R> cppFunction("IntegerVector fastswap(const NumericMatrix x, const int p, \
                    const IntegerVector S_init, const IntegerVector fixed_in, \
                    const IntegerMatrix order) { return S_init; }")
R> str(fastswap)
function (x, p, S_init, fixed_in, order)  
R> 

So you may have a problem with your computer setup. But as there is little reproducible here nobody can say for sure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top