繁体   English   中英

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

[英]Error in compiling when installing Stan for R and when using Rcpp

我需要为数据分析类安装Rstan。 说明在http://code.google.com/p/stan/wiki/RStanGettingStarted上发布。 我正在运行Mac OS 10.5.8和R 2.15.1 GUI 1.52 Leopard构建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 =铛

CXX =铛++

正如另一个答案中提到的,第一步是让Rcpp在你的Mac上工作(即,至少传递hello world示例)。

以前Rcpp的类似问题: https ://stat.ethz.ch/pipermail/r-sig-mac/2010-July/007574.html

另外,从这个网页http://useyourloaf.com/blog/2011/03/21/compiler-options-in-xcode-gcc-or-llvm.html看来,gcc 4.2和4.0似乎都在Xcode 3.14中(不确定,因为它没有说它是3.14)。 所以尽量确保R使用gcc 4.2.1很重要。 在终端中执行以下操作将显示当前版本的gcc。

$ g ++ -v

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM