Problem compiling Stan code

rstan

#1

Hi,

I’ve recently upgraded my MacOS, and consequently some other software too - such as the xtools command line compiler stuff.

I am now having problems with RStan (I have previously had a functioning installation), although since I am not currently a daily user of RStan I cannot state that the problem followed the OS upgrades.

I have tried uninstalling RStan and reinstalling as per the github getting started page, having read about similar issues on this forum. And simplified my .R/Makevars file.

But when I run stan.mod <- stan_model('p1_p2_o.stan'), I am getting:

Error in compileCode(f, code, language = language, verbose = verbose) :
  Compilation ERROR, function(s)/method(s) not created! In file included from filef6bf407f62b.cpp:8:
In file included from /Users/lfslbx/Library/R/3.5/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Users/lfslbx/Library/R/3.5/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Users/lfslbx/Library/R/3.5/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Users/lfslbx/Library/R/3.5/library/StanHeaders/include/stan/math/rev/core.hpp:4:
In file included from /Users/lfslbx/Library/R/3.5/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:
In file included from /Users/lfslbx/Library/R/3.5/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:8:
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.
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB filef6bf407f62b.cpp 2> filef6bf407f62b.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

Any suggestions welcomed.

The standard information follows…

Operating system: MacOS 10.14.1 (Mojave)

RStan version: 2.18.2

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

# The following statements are required to use the clang4 binary
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
# End clang4 inclusion statements
  # The following statement changes the Fortran linking path
  FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0
  # End Fortran linking path statement

Output of devtools::session_info("rstan")

Session info ------------------------------------------------------------------
 setting  value
 version  R version 3.5.1 (2018-07-02)
 system   x86_64, darwin15.6.0
 ui       X11
 language (EN)
 collate  en_GB.UTF-8
 tz       Europe/London
 date     2018-11-27

Packages ----------------------------------------------------------------------
 package      * version   date       source
 assertthat     0.2.0     2017-04-11 CRAN (R 3.5.0)
 backports      1.1.2     2017-12-13 CRAN (R 3.5.0)
 BH             1.66.0-1  2018-02-13 CRAN (R 3.5.0)
 callr          2.0.4     2018-05-15 CRAN (R 3.5.0)
 cli            1.0.0     2017-11-05 CRAN (R 3.5.0)
 colorspace     1.3-2     2016-12-14 CRAN (R 3.5.0)
 compiler       3.5.1     2018-07-05 local
 crayon         1.3.4     2017-09-16 CRAN (R 3.5.0)
 desc           1.2.0     2018-05-01 CRAN (R 3.5.0)
 dichromat      2.0-0     2013-01-24 CRAN (R 3.5.0)
 digest         0.6.15    2018-01-28 CRAN (R 3.5.0)
 ggplot2      * 3.0.0     2018-07-03 CRAN (R 3.5.0)
 glue           1.2.0     2017-10-29 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)
 loo            2.0.0     2018-04-11 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)
 matrixStats    0.53.1    2018-02-11 CRAN (R 3.5.0)
 methods      * 3.5.1     2018-07-05 local
 mgcv           1.8-24    2018-06-23 CRAN (R 3.5.1)
 munsell        0.4.3     2016-02-13 CRAN (R 3.5.0)
 nlme           3.1-137   2018-04-07 CRAN (R 3.5.1)
 parallel       3.5.1     2018-07-05 local
 pillar         1.2.2     2018-04-26 CRAN (R 3.5.0)
 pkgbuild       1.0.2     2018-10-16 CRAN (R 3.5.0)
 plyr           1.8.4     2016-06-08 CRAN (R 3.5.0)
 praise         1.0.0     2015-08-11 CRAN (R 3.5.0)
 prettyunits    1.0.2     2015-07-13 CRAN (R 3.5.0)
 processx       3.1.0     2018-05-15 CRAN (R 3.5.0)
 R6             2.2.2     2017-06-17 CRAN (R 3.5.0)
 RColorBrewer   1.1-2     2014-12-07 CRAN (R 3.5.0)
 Rcpp           0.12.17   2018-05-18 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.0     2018-02-20 CRAN (R 3.5.0)
 rprojroot      1.3-2     2018-01-03 CRAN (R 3.5.0)
 rstan        * 2.18.2    2018-11-07 CRAN (R 3.5.0)
 scales         0.5.0     2017-08-24 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.2     2018-05-02 CRAN (R 3.5.0)
 stringr        1.3.1     2018-05-10 CRAN (R 3.5.0)
 testthat       2.0.0     2017-12-13 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.3     2018-01-03 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)

#2

Cancel that.

I changed the /usr/local/clang4/bin/clang and /usr/local/clang4/bin/clang++ references in .R/Makevars to /usr/bin/clang and /usr/bin/clang++ and that seems to be good now.

I dropped the LDFLAGS=-L/usr/local/clang4/lib too, which seems sensible if I’m not using that version of clang.