Question

I am getting the following strange error:

> sourceCpp( "comp.Cpp" )
Warning message:
In sourceCpp("comp.Cpp") :
No Rcpp::export attributes or RCPP_MODULE declarations found in source

when I use sourceCpp. The "comp.Cpp" file looks like this:

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp:export]]
RcppExport SEXP comp(int n){
    int i;
    Rcpp::NumericVector product(n);
    for(i=0;i<n;i++){
        product[i]=i;
    }
    return(product);
}

I tried updating my operating system to Maverick (and then had to reinstall Xcode command line tools and some other things) but this error predates that. I can make the test package and install it and run the hello world it provides, so the Rcpp package is mostly working. I also get another error from running in R:

cppFunction( "
    int useCpp11() {
        auto x = 10;
        return x;
    }
", plugins=c("cpp11" ) )

which is

llvm-g++-4.2 -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include     -I/usr/local/include  -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include"   -std=c++11  -fPIC  -mtune=core2  -O3    -c file69810a85a0d.cpp -o file69810a85a0d.o 
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput,  : 
  Error 1 occurred building shared library.
cc1plus: error: unrecognized command line option "-std=c++11"
make: *** [file69810a85a0d.o] Error 1

I don't know if these two things are related. I think something is happening with my compiler not playing well with attributes, but hunting around the internet hasn't educated me sufficiently to understand that.

Any help would be greatly appreciated.

Was it helpful?

Solution

Change "[[Rcpp:export]]" by "[[Rcpp::export]]".

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
SEXP comp(int n){
    int i;
    Rcpp::NumericVector product(n);
    for(i=0;i<n;i++){
        product[i]=i;
    }
    return(product);
}

OTHER TIPS

Your compiler is too old for the C++11 flag. And the error message is very clear about it.

Try -std=c++0x as well as upgrading to Xcode 5 (which has its own set of issues -- but those are well documented here).

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