我需要为数据分析课安装 Rstan。说明张贴在这里 http://code.google.com/p/stan/wiki/RStanGettingStarted .我正在运行 Mac OS 10.5.8 和 R 2.15.1 GUI 1.52 Leopard build 32 位 (6188)。我刚刚安装了 Xcode 3.1.4 版,这是与 leopard 兼容的 Xcode c++ 编译器(我必须获得一个 mac 开发者帐户才能执行此操作)。
根据 Stan 安装说明,我输入了以下代码以查看我的编译器是否正常工作:
library(inline)
library(Rcpp)
src <- '
std::vector<std::string> s;
s.push_back("hello");
s.push_back("world");
return Rcpp::wrap(s);
'
hellofun <- cxxfunction(body = src, includes = '', plugin = 'Rcpp', verbose = FALSE)
cat(hellofun(), '\n')
它返回以下错误:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created!
Library/Frameworks/R.framework/Versions/2.15/Resources/library/
Rcpp/include/Rcpp/internal/export.h: In function ‘void
Rcpp::internal::export_range__dispatch(SEXPREC*, InputIterator,
Rcpp::traits::r_type_primitive_tag)’:
/Library/Frameworks/R.framework/Versions/2.15/Resources/
library/Rcpp/include/Rcpp/internal/export.h:56: internal
compiler error: Bus error
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://developer.apple.com/bugreporter> for
instructions.
make: *** [file795214e66510.o] Error 1
In addition: Warning message:
running command '/Library/Frameworks/R.framework/Resources/bin/
R CMD SHLIB file795214e66510.cpp 2>
file795214e66510.cpp.err.txt' had status 1
当我尝试安装 stan 时:
install.packages('rstan', type = 'source') ]
我收到这个警告: 警告信息: 在 install.packages("rstan", type = "source") 中: 包“rstan”的安装具有非零退出状态
我不知道 C++ 是如何工作的。我所有的编码经验都在 R 中,之前不需要编译成 C++。在过去 4 个小时左右的时间里,我一直在努力找出问题所在,一遍又一遍地用谷歌搜索这些错误消息,但运气不佳。任何帮助将不胜感激,并且还将帮助我类其他大约 10 名遇到相同或类似问题的学生。非常非常感谢你。
最佳答案
在我看来,这看起来像是安装 C++ 编译器或安装 Rcpp 包的问题,而不是 rstan 包的问题。然而,如果 g++ 给你带来了一个棘手的问题,一个替代方案是 clang 编译器,如果你用这两行创建 $HOME/.R/Makevars,它应该与 Rcpp 和 rstan 一起工作
CC= clang
CXX=clang++
关于c++ - 安装 Stan for R 和使用 Rcpp 时编译出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12755180/