c++ - 安装 Stan for R 和使用 Rcpp 时编译出错

标签 c++ xcode r compiler-construction stan

我需要为数据分析课安装 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/

相关文章:

c++ - 每当包含 windows.h 时都会出现大量编译错误,我的环境是 visual studio 2013 in win 7

c++ - 嵌套类的模板模板参数的可变类型模板参数和非类型模板参数如何相互约束?

r - 使用 purrr、broom 从许多单变量模型中获得整洁的输出

r - 如何使用 ggplot2 或 R 中的其他方式绘制矩阵中的数字并着色?这些数字是 vcf 文件中的 snp 计数

c++ - 使用 <math.h> 的二次公式中 sqrt() 的意外结果

c++ - 纯虚函数会阻止隐式生成的 move 构造函数吗?

iphone - UITextView 对齐方式正在自行更改

ios - 获取最后十个 firebase 值并将它们分配给十个 UIButton 的标题

ios - 下载音频文件并保存在照片库中,最后播放该音频

performance - 如何使计算/插入日期差异列更快?