RStan install problem on Mac (Nojave)

Installation question below.

  • Operating System macOS Mojave 10.14
  • RStan Version 2.17.4
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))

CC=/usr/local/clang4/bin/clang
CXX=/usr/local/clang4/bin/clang++
CXX1X=/usr/local/clang4/bin/clang++
CXX98=/usr/local/clang4/bin/clang++
CXX11=/usr/local/clang4/bin/clang++
CXX14=/usr/local/clang4/bin/clang++
CXX17=/usr/local/clang4/bin/clang++
LDFLAGS=-L/usr/local/clang4/lib

  • Output of devtools::session_info("rstan")

devtools::session_info(“rstan”)
Session info ------------------------------------------------
setting value
version R version 3.5.1 (2018-07-02)
system x86_64, darwin15.6.0
ui RStudio (1.2.1049)
language (EN)
collate en_US.UTF-8
tz Europe/Berlin
date 2018-10-14

Packages ----------------------------------------------------
package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.5.0)
BH 1.66.0-1 2018-02-13 CRAN (R 3.5.0)
cli 1.0.1 2018-09-25 CRAN (R 3.5.0)
colorspace 1.3-2 2016-12-14 CRAN (R 3.5.0)
crayon 1.3.4 2017-09-16 CRAN (R 3.5.0)
digest 0.6.18 2018-10-10 CRAN (R 3.5.0)
fansi 0.4.0 2018-10-05 CRAN (R 3.5.0)
ggplot2 * 3.0.0 2018-07-03 CRAN (R 3.5.0)
glue 1.3.0 2018-07-17 CRAN (R 3.5.0)
graphics * 3.5.1 2018-07-05 local
grDevices * 3.5.1 2018-07-05 local
grid 3.5.1 2018-07-05 local
gridExtra 2.3 2017-09-09 CRAN (R 3.5.0)
gtable 0.2.0 2016-02-26 CRAN (R 3.5.0)
inline 0.3.15 2018-05-18 CRAN (R 3.5.0)
labeling 0.3 2014-08-23 CRAN (R 3.5.0)
lattice 0.20-35 2017-03-25 CRAN (R 3.5.1)
lazyeval 0.2.1 2017-10-29 CRAN (R 3.5.0)
magrittr 1.5 2014-11-22 CRAN (R 3.5.0)
MASS 7.3-50 2018-04-30 CRAN (R 3.5.1)
Matrix 1.2-14 2018-04-13 CRAN (R 3.5.1)
methods * 3.5.1 2018-07-05 local
mgcv 1.8-24 2018-06-23 CRAN (R 3.5.1)
munsell 0.5.0 2018-06-12 CRAN (R 3.5.0)
nlme 3.1-137 2018-04-07 CRAN (R 3.5.1)
pillar 1.3.0 2018-07-14 CRAN (R 3.5.0)
plyr 1.8.4 2016-06-08 CRAN (R 3.5.0)
R6 2.3.0 2018-10-04 CRAN (R 3.5.0)
RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.5.0)
Rcpp * 0.12.19 2018-10-01 CRAN (R 3.5.0)
RcppEigen 0.3.3.4.0 2018-02-07 CRAN (R 3.5.0)
reshape2 1.4.3 2017-12-11 CRAN (R 3.5.0)
rlang 0.2.2 2018-08-16 CRAN (R 3.5.0)
rstan * 2.17.4 2018-10-01 CRAN (R 3.5.0)
scales 1.0.0 2018-08-09 CRAN (R 3.5.0)
StanHeaders * 2.18.0 2018-10-07 CRAN (R 3.5.0)
stats * 3.5.1 2018-07-05 local
stats4 3.5.1 2018-07-05 local
stringi 1.2.4 2018-07-20 CRAN (R 3.5.0)
stringr 1.3.1 2018-05-10 CRAN (R 3.5.0)
tibble 1.4.2 2018-01-22 CRAN (R 3.5.0)
tools 3.5.1 2018-07-05 local
utf8 1.1.4 2018-05-24 CRAN (R 3.5.0)
utils * 3.5.1 2018-07-05 local
viridisLite 0.3.0 2018-02-01 CRAN (R 3.5.0)
withr 2.1.2 2018-03-15 CRAN (R 3.5.0)

My question: I am getting the following error on test. Can someone help?

fx ← inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’

  • return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
  • ’ )
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

ERROR(s) during compilation: source code errors or compiler configuration errors!

Program source:
1:
2: // includes from the plugin
3: #include <R.h>
4: #include <Rdefines.h>
5: #include <R_ext/Error.h>
6:
7:
8: // user includes
9:
10:
11: // declarations
12: extern “C” {
13: SEXP file7517865c4a9( SEXP x, SEXP y) ;
14: }
15:
16: // definition
17:
18: SEXP file7517865c4a9( SEXP x, SEXP y ){
19:
20: return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
21:
22: Rf_warning(“your C++ program does not return anything”);
23: return R_NilValue ;
24: }
25:
26:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file7517865c4a9.cpp 2> file7517865c4a9.cpp.err.txt’ had status 1

Does this help?

This didn’t solve the problem, now I get another error message, but it helped in that it has something to do with Command Line Tools. I was under the impression that I had both xcode and CLT installed, as that is the first thing I do. I will report if I fail to figure out what’s missing.

You may not require Xcode. I have an install using only CLT which compiles Stan code properly.

No, this has definitely not worked for me. I am working on installing xcode (i had installed a beta edition, don‘t know how that happened). I will report tomorrow.

Wow, this should not be so hard.

You followed these steps or similar?

[Xcode CL Install Instructions] http://railsapps.github.io/xcode-command-line-tools.html

I did something similar. The instructions you link to assume high sierra but i have mojave. Does that matter? I will redo these steps tomorrow and report, maybe i missed a step.

I believe that the only relevant step is entering this into terminal

$ xcode-select --install

Yes, i had done that.

I solved the problem. Just for the next person who runs into this problem, I wanted to document my failures.

I installed xcode, deleted my R install and RStudio, and reinstalled these and then started the rstan install from scratch, following the steps laid out on mc-stan.org.

Then I got a new error message:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from file10025f51dc6d.cpp:3:
In file included from /Library/Frameworks/R.framework/Resources/include/R.h:47:
In file included from /usr/local/clang4/bin/…/include/c++/v1/cstdlib:86:
/usr/local/clang4/bin/…/include/c++/v1/stdlib.h:94:15: fatal error: ‘stdlib.h’ file not found
#include_next <stdlib.h>
^~~~~~~~~~
1 error generated.
make: *** [file10025f51dc6d.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file10025f51dc6d.cpp 2> file10025f51dc6d.cpp.err.txt’ had status 1

The stdlib.h file does not exist on my hard drive.

My Makevars looks like this:

LDFLAGS= -L/usr/local/clang4/lib
CC=/usr/local/clang4/bin/clang
CXX=/usr/local/clang4/bin/clang++
CXX1X=/usr/local/clang4/bin/clang++
CXX98=/usr/local/clang4/bin/clang++
CXX11=/usr/local/clang4/bin/clang++
CXX14=/usr/local/clang4/bin/clang++
CXX17=/usr/local/clang4/bin/clang++

CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined -Wno-unknown-pragmas

CC=clang
CXX14=clang++ -arch x86_64 -ftemplate-depth-256

Command line tools are installed too:

Shravans-MBP:~ shravanvasishth$ xcode-select --install
xcode-select: error: command line tools are already installed, use “Software Update” to install updates

Googling for the stdlib.h error, I found this exchange:

https://github.com/stan-dev/rstan/issues/527

At the very end, Ben says we have to run

Sys.setenv(USE_CXX14 = 1)

Once I did that, test test succeeds. Ben says he won't explain in polite company why this is necessary. Is it possible to write this step into the installation guide for now? I mean here (here). It would have saved me a lot of time if the workaround was mentioned there.

Checking your installation

  1. Restart R after the installation and, before loading RStan, verify that no objects created by an older version of RStan are (perhaps auto-)loaded into R.

  2. Verify that your toolchain works by executing the code below in R and checking that it returns the value 10:

fx <- inline::cxxfunction( signature(x = "integer", y = "numeric" ) , '
	return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
' ) fx( 2L, 5 ) # should be 10



3 Likes

The Sys.setenv(USE_CXX=1) is probably not necessary anymore now that rstan 2.18.1 is on CRAN (source only, no binaries yet).

I’m not going to mess with a good thing.

Well, rstan 2.17.4 wasn’t all that good, and wasn’t even supposed to exist but CRAN made me upload something that was nominally compatible with StanHeaders 2.17.x and StanHeaders 2.18.x. You are going to need rstan 2.18.1 eventually for the map_rect, threading, etc and I am 99% sure installing it is not going to break anything.

OK. I installed 2.18.2 on my machines today. Everything seems to have worked fine.

1 Like