Installation error

I’m getting:

stanc.cpp:21:28: fatal error: stan/version.hpp: No such file or directory
#include <stan/version.hpp>
^
compilation terminated.
make: *** [stanc.o] Error 1
ERROR: compilation failed for package ‘rstan’

Details:

  • Operating System: CentOS Linux release 7.6.1810 (Core)
  • RStan Version: 2.19.2
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
    CXX14 = g++ -std=c++1y -Wno-unused-variable -Wno-unused-function -fPIC
  • Output of devtools::session_info("rstan")
    ─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    setting value
    version R version 3.5.1 (2018-07-02)
    os CentOS Linux 7 (Core)
    system x86_64, linux-gnu
    ui RStudio
    language (EN)
    collate en_US.UTF-8
    ctype en_US.UTF-8
    tz America/New_York
    date 2019-07-13

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.5.1)
backports 1.1.4 2019-04-10 [1] CRAN (R 3.5.1)
BH 1.69.0-1 2019-01-07 [1] CRAN (R 3.5.1)
callr 3.3.0 2019-07-04 [1] CRAN (R 3.5.1)
checkmate 1.9.4 2019-07-04 [1] CRAN (R 3.5.1)
cli 1.1.0 2019-03-19 [1] CRAN (R 3.5.1)
colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.5.1)
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.1)
desc 1.2.0 2018-05-01 [2] CRAN (R 3.5.1)
digest 0.6.20 2019-07-04 [1] CRAN (R 3.5.1)
ellipsis 0.2.0.1 2019-07-02 [1] CRAN (R 3.5.1)
fansi 0.4.0 2018-10-05 [1] CRAN (R 3.5.1)
ggplot2 3.2.0 2019-06-16 [1] CRAN (R 3.5.1)
glue 1.3.1 2019-03-12 [1] CRAN (R 3.5.1)
gridExtra 2.3 2017-09-09 [1] CRAN (R 3.5.1)
gtable 0.3.0 2019-03-25 [1] CRAN (R 3.5.1)
inline 0.3.15 2018-05-18 [1] CRAN (R 3.5.1)
labeling 0.3 2014-08-23 [1] CRAN (R 3.5.1)
lattice 0.20-35 2017-03-25 [2] CRAN (R 3.5.1)
lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.5.1)
loo 2.1.0 2019-03-13 [1] CRAN (R 3.5.1)
magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.1)
MASS 7.3-50 2018-04-30 [2] CRAN (R 3.5.1)
Matrix 1.2-14 2018-04-13 [2] CRAN (R 3.5.1)
matrixStats 0.54.0 2018-07-23 [1] CRAN (R 3.5.1)
mgcv 1.8-24 2018-06-23 [2] CRAN (R 3.5.1)
munsell 0.5.0 2018-06-12 [1] CRAN (R 3.5.1)
nlme 3.1-137 2018-04-07 [2] CRAN (R 3.5.1)
pillar 1.4.2 2019-06-29 [1] CRAN (R 3.5.1)
pkgbuild 1.0.3 2019-03-20 [1] CRAN (R 3.5.1)
pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.5.1)
plyr 1.8.4 2016-06-08 [1] CRAN (R 3.5.1)
prettyunits 1.0.2 2015-07-13 [2] CRAN (R 3.5.1)
processx 3.4.0 2019-07-03 [1] CRAN (R 3.5.1)
ps 1.3.0 2018-12-21 [2] CRAN (R 3.5.1)
R6 2.4.0 2019-02-14 [1] CRAN (R 3.5.1)
RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.5.1)
Rcpp 1.0.1 2019-03-17 [1] CRAN (R 3.5.1)
RcppEigen 0.3.3.5.0 2018-11-24 [1] CRAN (R 3.5.1)
reshape2 1.4.3 2017-12-11 [1] CRAN (R 3.5.1)
rlang 0.4.0 2019-06-25 [1] CRAN (R 3.5.1)
rprojroot 1.3-2 2018-01-03 [2] CRAN (R 3.5.1)
rstan 2.18.2 2018-11-07 [1] CRAN (R 3.5.1)
scales 1.0.0 2018-08-09 [1] CRAN (R 3.5.1)
StanHeaders 2.18.1-10 2019-06-14 [1] CRAN (R 3.5.1)
stringi 1.4.3 2019-03-12 [1] CRAN (R 3.5.1)
stringr 1.4.0 2019-02-10 [1] CRAN (R 3.5.1)
tibble 2.1.3 2019-06-06 [1] CRAN (R 3.5.1)
utf8 1.1.4 2018-05-24 [1] CRAN (R 3.5.1)
vctrs 0.2.0 2019-07-05 [1] CRAN (R 3.5.1)
viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.5.1)
withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.1)
zeallot 0.1.0 2018-01-28 [1] CRAN (R 3.5.1)

[1] /gpfs/commons/home/daknowles/R/x86_64-redhat-linux-gnu-library/3.5
[2] /usr/lib64/R/library
[3] /usr/share/R/library

I am very beginner of R and I also encounter the installation error of rstan.

I struggled 2 days, but I cannot overcome, thus I removed the R and reinstalled all softwares related R. Then installation goes well.

Of course, I know that it is not a desired answer, but I overcame the installation error in this way yesterday.

This is often due to trying to install StanHeaders or RStan while the RStan package is already loaded, perhaps due to autoloading old stanfit objects through the .RData file. In which case, remove the .RData file from the disk, start a clean R session, remove RStan and possibly StanHeaders, reinstall them, possibly restart R, and it should be fine.

Jean - thanks but this is on a cluster so I can’t remove/reinstall R.

Ben - thanks but still getting the same error. Everything seems fine on R3.6 for me on Mac so maybe I’ll just try to get our sysadmins to install 3.6 on the cluster and see if that helps.

So this is still an issue for me on both R3.5 and 3.6 on linux. I’ve tried clearing out all my packages, still no luck (and still the same error).

I’ve also tried installing from the github rstan develop branch… same error.

This looks like a StanHeaders thing rather than a rstan thing. What is

grep("version.hpp", dir(system.file(package = "StanHeaders"), 
                        recursive = TRUE), 
     value = TRUE)

“include/src/stan/version.hpp” “include/stan/math/version.hpp”

StanHeaders has “successfully” installed as far as I can tell.

OK, then it is most likely something with the include path. When you do

library(rstan)
example(stan_model, run.dontrun = TRUE)

what is the line in the output with g++ ... or clang++ ...?

This seems like a catch-22, I can’t library(rstan) without successfully installing right?

Or just what is the line starting with g++ or clang++ when you try to install it and it tries to compile stanc.cpp?

Thanks Ben, looking at that line carefully showed my problem. I have a line in my .Rprofile which does cat("Sourced .Rprofile") because I was having some issue on the cluster where it wasn’t getting sourced at startup. The rstan install must run Rscript at some point to query where StanHeaders are, because the path it was getting was something like Sourced .Rprofile<correctpath> if that makes sense. Removed that line from my .Rprofile and fingers crossed it’s installing now!

I’ll know not to do that in future!

Thanks again.

That is true

Ha. What’s even better is if I just had a “\n” at the end of my cat like I should, the grep would have solved the problem!

So… my next problem is compiling 8schools.stan. Our cluster has gcc4.8.5 by default (rstan requires 4.9 I realize): compilation dies with an error that looks like maybe a minor difference between c++1y and c++14 (error: ‘std::index_sequence’ has not been declared).

With gcc6.2.0 I get the CentOS 7 problem alluded to here:


i.e.

/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20’ not found

but the export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/usr/local/lib64:/usr/lib64 fix doesn’t help, I just get

/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20’ not found

instead (note /usr/lib64 instead of just /lib64/)

gcc8.2.0 just segfaults :)