Installing RStan in RHEL with -std=c++11 flag

I followed the recently updated instructions for installing RStan in Linux, but got a lot of errors while compiling from source. The first two errors were:

In file included from /usr/lib64/R/library/StanHeaders/include/src/stan/lang/ast.hpp:103:0,
                 from /usr/lib64/R/library/StanHeaders/include/src/stan/lang/ast_def.cpp:7,
                 from lang__ast_def.cpp:18:
/usr/lib64/R/library/StanHeaders/include/src/stan/lang/ast/node/map_rect.hpp:27:48: error: ‘>>’ should be ‘> >’ within a nested template argument list
   static std::vector<std::pair<int, std::string>>& registered_calls() {
                                                ^
/usr/lib64/R/library/StanHeaders/include/src/stan/lang/ast/node/map_rect.hpp: In static member function ‘static std::vector<std::pair<int, std::basic_string<char> > >& stan::lang::map_rect::registered_calls()’:
/usr/lib64/R/library/StanHeaders/include/src/stan/lang/ast/node/map_rect.hpp:28:50: error: ‘>>’ should be ‘> >’ within a nested template argument list
     static std::vector<std::pair<int, std::string>> REGISTERED_CALLS_;
                                                  ^

The full installation log is attached.

I got the compile to succeed by adding “-std=c++11” to the CXX14FLAGS in .R/Makevars. Note: I did this based on some suggestion on stackexchange I found by searching on the text of one of those errors, not because I have any idea what I’m doing.

So I wrote this post to share my experience, but also because I am hoping to get confirmation that adding std=c++11 won’t have some subtle unintended consequence. If that was the right thing to do, then maybe it should be added to the installation instructions.

Here are the details of my system:

  • Operating System
    Red Hat Enterprise Linux Workstation release 7.5 (Maipo)
  • RStan Version
> rstan::stan_version()
[1] "2.18.0"
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
CXX14FLAGS=-O3 -mtune=native -march=native -std=c++11 -Wno-unused-variable -Wno-unused-function -fPIC
CXX14 = g++

CXX14FLAGS+=-flto -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations
  • Output of devtools::session_info("rstan") [note: I installed devtools to run this… who knows if I would have had this problem if I had installed devtools first]
> devtools::session_info("rstan")
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.5.1 (2018-07-02)
 os       Red Hat Enterprise Linux    
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/Los_Angeles         
 date     2018-10-26                  

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package      * version   date       lib source        
 assertthat     0.2.0     2017-04-11 [2] CRAN (R 3.5.1)
 backports      1.1.2     2017-12-13 [1] CRAN (R 3.5.1)
 base64enc      0.1-3     2015-07-28 [2] CRAN (R 3.5.1)
 BH             1.66.0-1  2018-02-13 [2] CRAN (R 3.5.1)
 callr          3.0.0     2018-08-24 [1] CRAN (R 3.5.1)
 cli            1.0.1     2018-09-25 [2] CRAN (R 3.5.1)
 colorspace     1.3-2     2016-12-14 [2] CRAN (R 3.5.1)
 crayon         1.3.4     2017-09-16 [2] CRAN (R 3.5.1)
 desc           1.2.0     2018-05-01 [1] CRAN (R 3.5.1)
 digest         0.6.18    2018-10-10 [2] CRAN (R 3.5.1)
 fansi          0.4.0     2018-10-05 [2] CRAN (R 3.5.1)
 ggplot2        3.0.0     2018-07-03 [2] CRAN (R 3.5.1)
 glue           1.3.0     2018-07-17 [2] CRAN (R 3.5.1)
 gridExtra      2.3       2017-09-09 [2] CRAN (R 3.5.1)
 gtable         0.2.0     2016-02-26 [2] CRAN (R 3.5.1)
 inline         0.3.15    2018-05-18 [2] CRAN (R 3.5.1)
 labeling       0.3       2014-08-23 [2] CRAN (R 3.5.1)
 lattice        0.20-35   2017-03-25 [2] CRAN (R 3.5.1)
 lazyeval       0.2.1     2017-10-29 [2] CRAN (R 3.5.1)
 loo            2.0.0     2018-04-11 [2] CRAN (R 3.5.1)
 magrittr       1.5       2014-11-22 [2] 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 [2] 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 [2] CRAN (R 3.5.1)
 nlme           3.1-137   2018-04-07 [2] CRAN (R 3.5.1)
 pillar         1.3.0     2018-07-14 [2] CRAN (R 3.5.1)
 pkgbuild       1.0.2     2018-10-16 [1] CRAN (R 3.5.1)
 plyr           1.8.4     2016-06-08 [2] CRAN (R 3.5.1)
 prettyunits    1.0.2     2015-07-13 [1] CRAN (R 3.5.1)
 processx       3.2.0     2018-08-16 [1] CRAN (R 3.5.1)
 ps             1.2.0     2018-10-16 [1] CRAN (R 3.5.1)
 R6             2.3.0     2018-10-04 [2] CRAN (R 3.5.1)
 RColorBrewer   1.1-2     2014-12-07 [2] CRAN (R 3.5.1)
 Rcpp           0.12.19   2018-10-01 [1] CRAN (R 3.5.1)
 RcppEigen      0.3.3.4.0 2018-02-07 [2] CRAN (R 3.5.1)
 reshape2       1.4.3     2017-12-11 [2] CRAN (R 3.5.1)
 rlang          0.2.2     2018-08-16 [2] CRAN (R 3.5.1)
 rprojroot      1.3-2     2018-01-03 [1] CRAN (R 3.5.1)
 rstan          2.18.1    2018-10-16 [1] CRAN (R 3.5.1)
 scales         1.0.0     2018-08-09 [2] CRAN (R 3.5.1)
 StanHeaders    2.18.0    2018-10-07 [2] CRAN (R 3.5.1)
 stringi        1.2.4     2018-07-20 [2] CRAN (R 3.5.1)
 stringr        1.3.1     2018-05-10 [2] CRAN (R 3.5.1)
 tibble         1.4.2     2018-01-22 [2] CRAN (R 3.5.1)
 utf8           1.1.4     2018-05-24 [2] CRAN (R 3.5.1)
 viridisLite    0.3.0     2018-02-01 [2] CRAN (R 3.5.1)
 withr          2.1.2     2018-03-15 [2] CRAN (R 3.5.1)

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

install_rstan.txt (170.8 KB)

If anything it should be -std=c++1y or -std=c++14 depending on what compiler version you are using. But it should have been happening automatically. What is the output of

R CMD config CXX14STD

on that server?

The compiler I’m using is gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) .
Calling that command just returns a blank line.

[bfiles@localhost ~]$ R CMD config CXX14STD

[bfiles@localhost ~]$ 

I can report that rstan compiles successfully with the -std=c++1y flag. It’s entirely possible that this system is in some weird misconfigured state, but perhaps if anyone has a similar experience, this thread will help them find the solution.

4.8.x is officially speaking not supported by Stan. It may work for 2.18 but you should try to upgrade your compiler to whatever is the latest version of g++ or clang++ available to you in the RHEL repos