简体   繁体   English

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

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

I need to install Rstan for a data analysis class. 我需要为数据分析类安装Rstan。 The instructions are posted here http://code.google.com/p/stan/wiki/RStanGettingStarted . 说明在http://code.google.com/p/stan/wiki/RStanGettingStarted上发布。 I'm running Mac OS 10.5.8 and R 2.15.1 GUI 1.52 Leopard build 32-bit (6188). 我正在运行Mac OS 10.5.8和R 2.15.1 GUI 1.52 Leopard构建32位(6188)。 I just installed Xcode version 3.1.4, the Xcode c++ compiler that is compatible with leopard (I had to get a mac developer account to do this). 我刚刚安装了Xcode 3.1.4版,与leopard兼容的Xcode c ++编译器(我必须得到一个mac开发者帐户才能执行此操作)。

Per the Stan installation instruction, I entered the following code to see if my compiler was working: 根据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') 

It returns the following error: 它返回以下错误:

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

When I try to install stan: 当我尝试安装stan时:

 install.packages('rstan', type = 'source') ] 

I get this warning: Warning message: In install.packages("rstan", type = "source") : installation of package 'rstan' had non-zero exit status 我收到此警告:警告消息:在install.packages(“rstan”,type =“source”)中:软件包'rstan'的安装具有非零退出状态

I have no idea how C++ works. 我不知道C ++是如何工作的。 All of my coding experience is in R and has not before required compiling into C++. 我的所有编码经验都在R中,之前没有编译成C ++。 I've been trying really hard to figure out what's wrong for the last 4 hours or so, googling these error messages over and over without much luck. 我一直在努力弄清楚过去4个小时左右出了什么问题,一遍又一遍地搜索这些错误信息而没有太多运气。 Any help would be greatly appreciated and would also help about 10 other students in my class who are having identical or analogous problems. 任何帮助将不胜感激,也将帮助我班上其他10个有相同或类似问题的学生。 Thank you very, very much. 非常非常感谢你。

This looks to me like an issue with the installation of your C++ compiler or with your installation of the Rcpp package, rather than an issue with the rstan package. 这看起来像是安装C ++编译器或安装Rcpp软件包的问题,​​而不是rstan软件包的问题。 However, if g++ is causing an intractable problem for you, an alternative is the clang compiler, which should work with Rcpp and rstan if you create $HOME/.R/Makevars with these two lines 但是,如果g ++为你造成了一个棘手的问题,那么另一种选择是clang编译器,如果用这两行创建$ HOME / .R / Makevars,它应该与Rcpp和rstan一起使用

CC=clang CC =铛

CXX=clang++ CXX =铛++

As mentioned in another answer, the first step is to get Rcpp working on your Mac (ie,. at least pass the hello world example). 正如另一个答案中提到的,第一步是让Rcpp在你的Mac上工作(即,至少传递hello world示例)。

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

In addition, from this webpage http://useyourloaf.com/blog/2011/03/21/compiler-options-in-xcode-gcc-or-llvm.html , it seems that gcc 4.2 and 4.0 are both in Xcode 3.14 (not sure as it does not say it's 3.14). 另外,从这个网页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)。 So try to make sure gcc 4.2.1 is used by R is important. 所以尽量确保R使用gcc 4.2.1很重要。 Executing the following in a terminal will show what is the current version of gcc. 在终端中执行以下操作将显示当前版本的gcc。

$ g++ -v $ g ++ -v

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

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