我收到以下奇怪的错误:
> sourceCpp( "comp.Cpp" )
Warning message:
In sourceCpp("comp.Cpp") :
No Rcpp::export attributes or RCPP_MODULE declarations found in source
Run Code Online (Sandbox Code Playgroud)
当我使用sourceCpp时."comp.Cpp"文件如下所示:
#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);
}
Run Code Online (Sandbox Code Playgroud)
我尝试将我的操作系统更新为Maverick(然后不得不重新安装Xcode命令行工具和其他一些东西),但这个错误早于此.我可以制作测试包并安装它并运行它提供的hello world,因此Rcpp包主要工作.我在R中运行时还遇到另一个错误:
cppFunction( "
int useCpp11() {
auto x = 10;
return x;
}
", plugins=c("cpp11" ) )
Run Code Online (Sandbox Code Playgroud)
是的
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
Run Code Online (Sandbox Code Playgroud)
我不知道这两件事是否相关.我认为我的编译器不能很好地处理属性会发生一些事情,但是在互联网上搜索并没有让我充分了解这一点.
任何帮助将不胜感激.
通过"[[Rcpp :: export]]"更改"[[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);
}
Run Code Online (Sandbox Code Playgroud)