简体   繁体   中英

Error in compiling when installing Stan for R and when using Rcpp

I need to install Rstan for a data analysis class. The instructions are posted here 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). 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).

Per the Stan installation instruction, I entered the following code to see if my compiler was working:

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:

 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

I have no idea how C++ works. All of my coding experience is in R and has not before required compiling into 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. Any help would be greatly appreciated and would also help about 10 other students in my class who are having identical or analogous problems. 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. 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

CC=clang

CXX=clang++

As mentioned in another answer, the first step is to get Rcpp working on your Mac (ie,. at least pass the hello world example).

A similar issue for Rcpp previously: 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). So try to make sure gcc 4.2.1 is used by R is important. Executing the following in a terminal will show what is the current version of gcc.

$ g++ -v

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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