我收到以下奇怪的错误:
> sourceCpp( "comp.Cpp" )
Warning message:
In sourceCpp("comp.Cpp") :
No Rcpp::export attributes or RCPP_MODULE declarations found in source
当我使用 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);
}
我尝试将我的操作系统更新到 Maverick(然后不得不重新安装 Xcode 命令行工具和其他一些东西)但是这个错误早于那个。我可以制作测试包并安装它并运行它提供的 hello world,因此 Rcpp 包大部分都在工作。我还在 R 中运行时遇到另一个错误:
cppFunction( "
int useCpp11() {
auto x = 10;
return x;
}
", plugins=c("cpp11" ) )
这是
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
不知道这两件事有没有关系。我认为我的编译器无法很好地处理属性,但在互联网上搜索并没有给我足够的教育来理解这一点。
如有任何帮助,我们将不胜感激。
最佳答案
将“[[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);
}
关于c++ - 来自 Rcpp 的 sourceCpp 在规范示例中给出了奇怪的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21165591/