Installing rstan on RHEL 7 - ‘decay_t’ is not a member of ‘std’

Short summary of the problem -

We’re trying to install rstan on R 3.6.1. I’ve tried to follow all of the different compiler flags and things here but no luck. I’m seeing a different error than others also so figure I’d start a new thread.

>scl enable devtoolset-8

> gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr --mandir=/opt/rh/devtoolset-8/root/usr/share/man --infodir=/opt/rh/devtoolset-8/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)

tk80332e@a4303e1pdvml004:~> cat .R/Makevars
CXX14 = g++ -fPIC
CXX14FLAGS = -O3
CXX14PICFLAGS = -fpic
CXX14STD = -std=gnu++1y
CXXFLAGS = -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION
#CXX14FLAGS+= -std=c++1y  - i've tried this and -std=c++11.  -std=c++14 can't be found, throws error.

And the install error:

> install.packages("rstan")
Installing package into ‘/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/rstan_2.21.2.tar.gz'
Content type 'application/x-gzip' length 1152008 bytes (1.1 MB)
==================================================
downloaded 1.1 MB

* installing *source* package ‘rstan’ ...
** package ‘rstan’ successfully unpacked and MD5 sums checked
** using staged installation
** libs

g++ -fPIC -std=gnu++1y -I"/opt/R/3.6.1/lib64/R/include" -DNDEBUG -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"." -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DBOOST_NO_AUTO_PTR -D_REENTRANT -DSTAN_THREADS   -I"/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include" -I"/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/RcppEigen/include" -I"/opt/R/3.6.1/lib64/R/library/BH/include" -I"/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include" -I"/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/RcppParallel/include" -I/usr/local/include  -fpic  -O3 -c chains.cpp -o chains.o
In file included from /tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/arr/meta/is_vector.hpp:4:0,
                 from /tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/arr/meta/index_type.hpp:4,
                 from /tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/meta.hpp:5,
                 from /tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/arr/err/check_nonzero_size.hpp:4,
                 from /tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:4,
                 from chains.cpp:19:
/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/is_vector.hpp:23:21: error: ‘decay_t’ is not a member of ‘std’
     : bool_constant<std::decay_t<T>::RowsAtCompileTime == 1> {};
...
chains.cpp:580:55: error: no matching function for call to ‘mean(std::vector<double>&)’
   double var_within = stan::math::mean(split_chain_var);
                                                       ^
chains.cpp:580:55: note: candidates are:
In file included from chains.cpp:19:0:
/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:21:25: note: template<class T> stan::return_type_t<T> stan::math::mean(const std::vector<T>&)
 inline return_type_t<T> mean(const std::vector<T>& v) {
                         ^
/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:21:25: note:   template argument deduction/substitution failed:
/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:34:25: note: template<class T, int R, int C> stan::return_type_t<T> stan::math::mean(const Eigen::Matrix<T, R, C>&)
 inline return_type_t<T> mean(const Eigen::Matrix<T, R, C>& m) {
                         ^
/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:34:25: note:   template argument deduction/substitution failed:
chains.cpp:580:55: note:   ‘std::vector<double>’ is not derived from ‘const Eigen::Matrix<T, R, C>’
   double var_within = stan::math::mean(split_chain_var);
                                                       ^
make: *** [chains.o] Error 1
ERROR: compilation failed for package ‘rstan’
* removing ‘/tech/appl/default/user/tk80332e/R/x86_64-pc-linux-gnu-library/3.6/rstan’

The downloaded source packages are in
        ‘/tech/appl/default/user/tk80332e/tmp/RtmpZgfW8i/downloaded_packages’
Warning message:
In install.packages("rstan") :
  installation of package ‘rstan’ had non-zero exit status


I don’t know if I’m missing something or the pointers aren’t right, but the only error I’ve been able to reproduce is the ‘decay_t’ is not a member of ‘std’.

  • Operating System - RHEL7
  • RStan Version - 2.21.2
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
CXX14 = g++ -fPIC
CXX14FLAGS = -O3
CXX14PICFLAGS = -fpic
CXX14STD = -std=gnu++1y
  • Output of devtools::session_info("rstan")

Thanks in advance.

I suspect the g++ that R is calling is not 8.3.1, especially if the c++14 flag isn’t supported. I’m not sure how to investigate that, but there’s probably a way to get what compiler your R is using.

Maybe whatever process launches the R session needs to load up scl enable devtoolset-8 before it launches?

The statement from here: https://gcc.gnu.org/projects/cxx-status.html#cxx14 is that c++14 is the default in gcc 6.1 up.

Thanks @bbbales2! That was just the nudge I needed. When I started R I noticed my PATH and LD_LIBRARY_PATH didn’t have my devtoolset-8 in either variable, I set those to what the variables were outside of R, but still no luck.

Then I saw your note on c++14 is the standard, so I figured I would get rid of it in my Makevars file, and another thing I tried which I think was the magic sauce was to change:

CXX14 = g++ -fPIC

to point directly to my devtoolset-8 version:

CXX14 = /opt/rh/devtoolset-8/root/usr/bin/g++ -fPIC

in Makevars and that did the trick! The package installed no problem after that.

Thanks again, consider this resolved. Hopefully this will help someone else along the way :)

3 Likes