我正在尝试运行“与 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")
Run Code Online (Sandbox Code Playgroud)
这是消息错误:
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.
Run Code Online (Sandbox Code Playgroud)
看起来你有错别字:
Code <- '
#include <gsL/gsl_const_mksa.h> // decl of constants
Run Code Online (Sandbox Code Playgroud)
那应该是code <-小写的c,然后#include <gsl/gsl_const_mksa.h> 是小写的'ell'。
一般来说,我建议开启详细模式:
gslVolumes <- cppFunction(code, depends="RcppGSL", verbose=TRUE)
Run Code Online (Sandbox Code Playgroud)
哪个会告诉你
object code not found 从第一个错误开始,以及
file....cpp:10:63: fatal error: gsL/gsl_const_mksa.h: No such file or directory
关于丢失的标题。
但我现在确实看到,使用当前版本,我也得到__result not declared. 会调查。
编辑:这是一个错误/更改。当我写这一章时它起作用了,现在你需要
#include <gsl/gsl_const_mksa.h>从code作业中删除带有 的行
includes=...向cppFunction()调用添加一个新参数,如下所示:
更正的调用:
gslVolumes <- cppFunction(code, depends="RcppGSL",
includes="#include <gsl/gsl_const_mksa.h>")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1223 次 |
| 最近记录: |