加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – Rcpp代码示例cppFunction

发布时间:2020-12-16 09:48:12 所属栏目:百科 来源:网络整理
导读:我正在尝试运行“使用Rcpp进行无缝R和C集成”的代码(第32页,代码清单2.10)但是它给出了一个错误.有人可以向我解释为什么不工作?谢谢 Code - ' #include gsL/gsl_const_mksa.h // decl of constants std::vectordouble volumes() { std::vectordouble v(5);
我正在尝试运行“使用Rcpp进行无缝R和C集成”的代码(第32页,代码清单2.10)但是它给出了一个错误.有人可以向我解释为什么不工作?谢谢

Code <- ' 
#include <gsL/gsl_const_mksa.h>           // decl of constants 
std::vector<double> volumes() { 
std::vector<double> v(5); 
v[0] = GSL_CONST_MKSA_US_GALLON;       // 1 US gallon 
v[1] = GSL_CONST_MKSA_CANADIAN_GALLON; // 1 Canadian gallon 
v[2] = GSL_CONST_MKSA_UK_GALLON;       // 1 UK gallon 
v[3] = GSL_CONST_MKSA_QUART;           // 1 quart 
v[4] = GSL_CONST_MKSA_PINT;            // 1 pint 
return v; 
}' 

gslVolumes <- cppFunction(code,depends="RcppGSL")

这是消息错误:

file16e2b6cb966.cpp: In function ‘SEXPREC* sourceCpp_52966_volumes()’: 
file16e2b6cb966.cpp:30: error: ‘__result’ was not declared in this scope 
make: *** [file16e2b6cb966.o] Error 1 
llvm-g++-4.2 -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include -I/usr/local/include  -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/RcppGSL/include"    -fPIC  -mtune=core2 -g -O2  -c file16e2b6cb966.cpp -o file16e2b6cb966.o 
Erro em sourceCpp(code = code,env = env,rebuild = rebuild,showOutput = showOutput,: 
  Error 1 occurred building shared library.

解决方法

看起来你有错别字:

Code <- ' 
#include <gsL/gsl_const_mksa.h>           // decl of constants

这应该是代码< - 用小写c,然后#include< gsl / gsl_const_mksa.h>用小写’ell’.

一般来说,我建议打开详细模式:

gslVolumes <- cppFunction(code,depends="RcppGSL",verbose=TRUE)

本来会告诉你的

>从第一个错误中找不到对象代码,和
> file …. cpp:10:63:致命错误:gsL / gsl_const_mksa.h:没有这样的文件或目录

关于丢失的标题.

但我现在确实看到,对于当前版本,我也没有声明__result.将
调查.

编辑:这是一个错误/变化.它在我写这一章时起作用,现在你需要

>使用#include< gsl / gsl_const_mksa.h>删除该行从代码分配
>在cppFunction()调用中添加一个新的includes = …参数,如下所示:

更正的电话:

gslVolumes <- cppFunction(code,includes="#include <gsl/gsl_const_mksa.h>")

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读