RStan successfully installed but unable to compile model

Hi,

As the title says, I have installed RStan successfully but am unable to compile models.

For example, if I run example(stan_model, run.dontrun = TRUE) then I get the following error:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! file6d6a676427f9.cpp:6:36: warning: ISO C99 requires whitespace after the macro name [enabled by default]
 #define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
                                    ^
In file included from /home/eplas/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/mat/fun/ordered_constrain.hpp:6:0,
                 from /home/eplas/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/mat.hpp:41,
                 from /home/eplas/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/src/stan/model/log_prob_grad.hpp:4,
                 from /home/eplas/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/src/stan/model/test_gradients.hpp:7,
                 from /home/eplas/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/src/stan/services/diagnose/diagnose.hpp:10,
                 from /home/eplas/R/x86_64-pc-linux-gnu-library/3.4/rstan/include/

I’ve found a couple of other threads about this problem in the forum, but none of the solutions work for me. Namely:

Further system setup information is below.

Thanks,
James

  • Contents of ~/.R/Makevars
CXX14=g++ -std=c++1y -fPIC
  • RStan session_info
─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                                      
 version  R version 3.4.3 (2017-11-30)               
 os       Red Hat Enterprise Linux Server 7.8 (Maipo)
 system   x86_64, linux-gnu                          
 ui       RStudio                                    
 language (EN)                                       
 collate  en_US.UTF-8                                
 ctype    en_US.UTF-8                                
 tz       UTC                                        
 date     2020-05-27                                 

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────────
 package      * version   date       lib source        
 assertthat     0.2.0     2017-04-11 [2] CRAN (R 3.4.3)
 backports      1.1.4     2019-04-10 [1] CRAN (R 3.4.3)
 BH           * 1.72.0-3  2020-01-08 [1] CRAN (R 3.4.3)
 callr          3.3.2     2019-09-22 [1] CRAN (R 3.4.3)
 checkmate      2.0.0     2020-02-06 [1] CRAN (R 3.4.3)
 cli            1.1.0     2019-03-19 [1] CRAN (R 3.4.3)
 colorspace     1.3-2     2016-12-14 [2] CRAN (R 3.4.3)
 crayon         1.3.4     2017-09-16 [2] CRAN (R 3.4.3)
 desc           1.2.0     2018-05-01 [1] CRAN (R 3.4.3)
 dichromat      2.0-0     2013-01-24 [2] CRAN (R 3.4.3)
 digest         0.6.15    2018-01-28 [2] CRAN (R 3.4.3)
 ellipsis       0.3.0     2019-09-20 [1] CRAN (R 3.4.3)
 fansi          0.4.0     2018-10-05 [1] CRAN (R 3.4.3)
 ggplot2      * 3.2.1     2019-08-10 [1] CRAN (R 3.4.3)
 glue           1.3.1     2019-03-12 [1] CRAN (R 3.4.3)
 gridExtra      2.3       2017-09-09 [2] CRAN (R 3.4.3)
 gtable         0.2.0     2016-02-26 [2] CRAN (R 3.4.3)
 inline       * 0.3.15    2018-05-18 [1] CRAN (R 3.4.3)
 labeling       0.3       2014-08-23 [2] CRAN (R 3.4.3)
 lattice        0.20-35   2017-03-25 [2] CRAN (R 3.4.3)
 lazyeval       0.2.1     2017-10-29 [2] CRAN (R 3.4.3)
 loo            2.2.0     2019-12-19 [1] CRAN (R 3.4.3)
 magrittr       1.5       2014-11-22 [2] CRAN (R 3.4.3)
 MASS           7.3-47    2017-02-26 [2] CRAN (R 3.4.3)
 Matrix         1.2-12    2017-11-20 [2] CRAN (R 3.4.3)
 matrixStats    0.56.0    2020-03-13 [1] CRAN (R 3.4.3)
 mgcv           1.8-22    2017-09-24 [2] CRAN (R 3.4.3)
 munsell        0.4.3     2016-02-13 [2] CRAN (R 3.4.3)
 nlme           3.1-131   2017-02-06 [2] CRAN (R 3.4.3)
 pillar         1.4.2     2019-06-29 [1] CRAN (R 3.4.3)
 pkgbuild       1.0.5     2019-08-26 [1] CRAN (R 3.4.3)
 pkgconfig      2.0.3     2019-09-22 [1] CRAN (R 3.4.3)
 plyr           1.8.4     2016-06-08 [2] CRAN (R 3.4.3)
 prettyunits    1.0.2     2015-07-13 [1] CRAN (R 3.4.3)
 processx       3.4.1     2019-07-18 [1] CRAN (R 3.4.3)
 ps             1.3.0     2018-12-21 [1] CRAN (R 3.4.3)
 R6             2.4.0     2019-02-14 [1] CRAN (R 3.4.3)
 RColorBrewer   1.1-2     2014-12-07 [2] CRAN (R 3.4.3)
 Rcpp         * 1.0.2     2019-07-25 [1] CRAN (R 3.4.3)
 RcppEigen      0.3.3.5.0 2018-11-24 [1] CRAN (R 3.4.3)
 reshape2       1.4.3     2017-12-11 [2] CRAN (R 3.4.3)
 rlang          0.4.0     2019-06-25 [1] CRAN (R 3.4.3)
 rprojroot      1.3-2     2018-01-03 [1] CRAN (R 3.4.3)
 rstan        * 2.19.3    2020-02-11 [1] CRAN (R 3.4.3)
 scales         0.5.0     2017-08-24 [2] CRAN (R 3.4.3)
 StanHeaders  * 2.19.2    2020-02-11 [1] CRAN (R 3.4.3)
 stringi        1.2.2     2018-05-02 [2] CRAN (R 3.4.3)
 stringr        1.3.0     2018-02-19 [2] CRAN (R 3.4.3)
 tibble         2.1.3     2019-06-06 [1] CRAN (R 3.4.3)
 utf8           1.1.3     2018-01-03 [2] CRAN (R 3.4.3)
 vctrs          0.2.0     2019-07-05 [1] CRAN (R 3.4.3)
 viridisLite    0.3.0     2018-02-01 [2] CRAN (R 3.4.3)
 withr          2.1.2     2018-03-15 [1] CRAN (R 3.4.3)
 zeallot        0.1.0     2018-01-28 [1] CRAN (R 3.4.3)

[1] /home/user/R/x86_64-pc-linux-gnu-library/3.4
[2] /opt/R/3.4.3/lib64/R/library

Can you re-run with the verbose flag:

example(stan_model,run.dontrun = TRUE,verbose=TRUE)

And post the line that starts with error:?

You might also get a long list of warnings, you can hide those by adding -Wno-ignored-attributes to your makefile before running

1 Like

There are a couple such lines but here are the first few

/home/user/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/mat/functor/adj_jac_apply.hpp:31:32: error: ‘std::index_sequence’ has not been declared
                           std::index_sequence<I...> i) {
                                ^
/home/user/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/mat/functor/adj_jac_apply.hpp:31:46: error: expected ‘,’ or ‘...’ before ‘<’ token
                           std::index_sequence<I...> i) {
                                              ^
/home/user/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/mat/functor/adj_jac_apply.hpp: In function ‘constexpr auto stan::math::internal::apply(const F&, const Tuple&)’:
/home/user/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/mat/functor/adj_jac_apply.hpp:49:27: error: ‘make_index_sequence’ is not a member of ‘std’
   return apply_impl(f, t, std::make_index_sequence<std::tuple_size<Tuple>{}>{});

Just found a similar error in another thread (and this one). I suspect the problem is that I’m using an old compiler (GCC 4.8.5) and unfortunately I can’t upgrade this machine.

Yes, unfortunately that’s the case. Stan currently requires a c++14 compatible compiler, and 4.8.5 only has very limited support for c++14 features

Okay, thanks for confirming. I’ll figure out a workaround somehow.