Error in compileCode while installing (Mac)

Hi there,

I’m very new to rstan. I’m trying to download it onto my computer and it continuously comes up with an error and I’m not sure how to fix it. I’ve tried to download Rstan in Rstudio and R, with the same result. I’ve followed the instructions on the github diligently, so I’m not sure what went wrong. I downloaded xcode from the app store, as rstan requires and opened it before moving on with rstan installation.

  • Here is the error I get after installing Rstan and trying out the bit of code on the github website:**

    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 file17942230f0ad2( SEXP x, SEXP y) ;
    14: }
    15:
    16: // definition
    17:
    18: SEXP file17942230f0ad2( 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:
    running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file17942230f0ad2.cpp 2> file17942230f0ad2.cpp.err.txt’ had status 1


Here are other specs that might be useful:

  • Operating System : macOS High Sierra, Version 10.13.4

  • RStan Version : 2.17.3

  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars"))) :

CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined

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

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

Session info ----------------------------------------------------------
setting value
version R version 3.4.4 (2018-03-15)
system x86_64, darwin15.6.0
ui RStudio (1.0.143)
language (EN)
collate en_US.UTF-8
tz Europe/Berlin

Packages --------------------------------------------------------------
package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.4.0)
BH 1.66.0-1 2018-02-13 CRAN (R 3.4.3)
cli 1.0.0 2017-11-05 CRAN (R 3.4.2)
colorspace 1.3-2 2016-12-14 CRAN (R 3.4.0)
crayon 1.3.4 2017-09-16 CRAN (R 3.4.1)
dichromat 2.0-0 2013-01-24 CRAN (R 3.4.0)
digest 0.6.15 2018-01-28 CRAN (R 3.4.3)
ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.4.0)
glue 1.2.0 2017-10-29 CRAN (R 3.4.2)
graphics * 3.4.4 2018-03-15 local
grDevices * 3.4.4 2018-03-15 local
grid 3.4.4 2018-03-15 local
gridExtra 2.3 2017-09-09 CRAN (R 3.4.1)
gtable 0.2.0 2016-02-26 CRAN (R 3.4.0)
inline 0.3.14 2015-04-13 CRAN (R 3.4.0)
labeling 0.3 2014-08-23 CRAN (R 3.4.0)
lattice 0.20-35 2017-03-25 CRAN (R 3.4.4)
lazyeval 0.2.1 2017-10-29 CRAN (R 3.4.2)
magrittr 1.5 2014-11-22 CRAN (R 3.4.0)
MASS 7.3-49 2018-02-23 CRAN (R 3.4.4)
Matrix 1.2-14 2018-04-09 CRAN (R 3.4.4)
methods * 3.4.4 2018-03-15 local
munsell 0.4.3 2016-02-13 CRAN (R 3.4.0)
pillar 1.2.2 2018-04-26 CRAN (R 3.4.4)
plyr 1.8.4 2016-06-08 CRAN (R 3.4.0)
R6 2.2.2 2017-06-17 CRAN (R 3.4.0)
RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.4.0)
Rcpp 0.12.16 2018-03-13 CRAN (R 3.4.4)
RcppEigen 0.3.3.4.0 2018-02-07 CRAN (R 3.4.3)
reshape2 1.4.3 2017-12-11 CRAN (R 3.4.3)
rlang 0.2.0 2018-02-20 CRAN (R 3.4.3)
rstan * 2.17.3 2018-01-20 CRAN (R 3.4.3)
scales 0.5.0 2017-08-24 CRAN (R 3.4.1)
StanHeaders * 2.17.2 2018-01-20 CRAN (R 3.4.3)
stats * 3.4.4 2018-03-15 local
stats4 3.4.4 2018-03-15 local
stringi 1.1.7 2018-03-12 CRAN (R 3.4.4)
stringr 1.3.0 2018-02-19 CRAN (R 3.4.3)
tibble 1.4.2 2018-01-22 CRAN (R 3.4.3)
tools 3.4.4 2018-03-15 local
utf8 1.1.3 2018-01-03 CRAN (R 3.4.3)
utils * 3.4.4 2018-03-15 local
viridisLite 0.3.0 2018-02-01 CRAN (R 3.4.3)

I googled parts of your error message

and found the suggestion to try running the following code in a terminal window (found /Applications/Utilities/Terminal.app):

xcode-select --install

Also, the following thread might have some more options for you if the above still doesn’t cut it:

2 Likes

That seems to have solved the problem. Thank you very much!