Installing rstan on RHEL7

Can you copy the part that has the string error: (with the trailing colon)?

The total output has 90 “error:”.
I just copy the final 2 and the rest is attached.
Thank you.

/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/function_signatures.h:1365:24: error: range-based ‘for’ loops are not allowed in C++98 mode
for (const auto& u : all_vector_types) {
/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/function_signatures.h:1366:57: error: no matching function for call to ‘stan::lang::function_signatures::rng_return_type(const int&, const int&)’
add(“weibull_rng”, rng_return_type<double_type>(t, u), t, u);

rstan installing error on Red 20181029.pdf (162.4 KB)

You may need to call

Sys.setenv(USE_CXX14 = 1)

once before installing.

I did that.
The same error comes:

In file included from /home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast.hpp:65:0,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast_def.cpp:7,
from lang__ast_def.cpp:18:
/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures.hpp:306:17: note: template stan::lang::expr_type stan::lang::function_signatures::rng_return_type(const stan::lang::expr_type&, const stan::lang::expr_type&, const stan::lang::expr_type&)
expr_type rng_return_type(const expr_type& t,
/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures.hpp:306:17: note: template argument deduction/substitution failed:
In file included from /home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures_def.hpp:486:0,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast_def.cpp:119,
from lang__ast_def.cpp:18:
/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/function_signatures.h:1366:57: note: cannot convert ‘t’ (type ‘const int’) to type ‘const stan::lang::expr_type&’
add(“weibull_rng”, rng_return_type<double_type>(t, u), t, u);
At global scope:
cc1plus: warning: unrecognized command line option “-Wno-ignored-attributes” [enabled by default]
make: *** [lang__ast_def.o] Error 1
ERROR: compilation failed for package ‘rstan’

  • removing ‘/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

The downloaded source packages are in

Somehow, it is not realizing that it is supposed to be using C++14. In a shell, what comes back after you execute R CMD config CXX14 ?

Also, what does g++ --version say?

Thank you for your quick response.

[root@euca-128-84-10-160 ~]# R CMD config CXX14


[root@euca-128-84-10-160 ~]# g++ --version

g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)

Copyright © 2015 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO


Technically, g++-4.8 is not sufficient because it does not implement any of the C++14 standard, although it does accept the -std=c++1y flag. On the other hand, Stan 2.18 technically isn’t using any of the C++14 syntax. It will probably work if you set

CXX14 = g++ -std=c++11

but you should look into getting a newer version of g++ or clang++ from the RHEL repos.

I tried “yum install gcc” as in , but with the following error. yum install others also have the same issue. Could you recommend a repo (url) for new g++?
Thank you.

Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 18 kB 00:00:00
Could not retrieve mirrorlist error was
14: curl#6 - “Could not resolve host:; Unknown error”

One of the configured repositories failed (Unknown),
and yum doesn’t have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work “fix” this:

 1. Contact the upstream for the repository and get them to fix the problem.

 2. Reconfigure the baseurl/etc. for the repository, to point to a working
    upstream. This is most often useful if you are using a newer
    distribution release than is supported by the repository (and the
    packages for the previous distribution release still work).

 3. Run the command with the repository temporarily disabled
        yum --disablerepo=<repoid> ...

 4. Disable the repository permanently, so yum won't use it by default. Yum
    will then just ignore the repository until you permanently enable it
    again or use --enablerepo for temporary usage:

        yum-config-manager --disable <repoid>
        subscription-manager repos --disable=<repoid>

 5. Configure the failing repository to be skipped, if it is unavailable.
    Note that yum will try to contact the repo. when it runs most commands,
    so will have to try and fail each time (and thus. yum will be be much
    slower). If it is a very temporary problem though, this is often a nice

        yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: euca2ools/7/x86_64

I think you need to look into the Red Hat Developer Toolset
but really if you have RHEL you usually have a system administrator who knows what additional repositories are out there and which are permitted under support constracts and so forth.

I followed the following advice from University service, and now the rstan is installed.

Please make sure devtoolset-7 (not Red Had Developer Toolkit) is installed:

sudo yum install centos-release-scl
sudo yum install devtoolset-7

It must also be enabled in your shell so it becomes the default g++ compiler:

scl enable devtoolset-7 bash

However, when I run

GMM.stan.model=stan_model(file=“GMMdesign20181030_standardize_noZ_redundant_1level.stan”,model_name = “GMM_stan”)

with the stan file
GMMdesign20181030_standardize_noZ_redundant_1level.stan (1.8 KB)

the following error comes:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /usr/include/c++/4.8.2/thread:35:0,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/functor/map_rect_concurrent.hpp:10,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/functor/map_rect.hpp:13,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat.hpp:262,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
from /usr/lib64/R/library/StanHeaders/include/stan/math.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from file6202730a0d5.cpp:8:
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler op
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/usr/lib64/R/bin/R CMD SHLIB file6202730a0d5.cpp 2> file6202730a0d5.cpp.err.txt’ had status 1

Try adding CXX14FLAGS+= -std=c++11 to your makefile. I am short on explanations, but our systems are very similar and specifying std fixes the same error for me.

As for where I got it, the error tells you to enable -std=c++11

It is not recognizing your newer C++ compiler. Check the step where you enable it to be the default compiler or perhaps specify g++-7 or whatever its version number is.

Solved by adding this to the final line of makefile.
Thank you.

That is only going to work for the 2.18.x release though. Soon, you are going to need to be using a later compiler.

So you think that Rcpp is still attempting to use the wrong version of gcc?

system('g++ -v') gives me 5.3.0 and I know that I couldn’t get rstan 2.18.1 to install until I recompiled gcc 5.3.0 with the matching gfortran, so at least install.packages is using the 5.3.0 version of gcc.

Do you have a way to verify that Rcpp using the right version of gcc? The stackoverflow method of forcing a gcc version (CXX14=g++-5.3) apparently does not work for gcc versions greater than 4.9. I know that I have gcc version 4.8.5 and 5.3.0 installed, but everything else seems to use 5.3.0.

@Peter_Adelman I think your setup is fine. But @Ziyi_Chen said that this error

was overcome by adding -std=c++11 to the makefile, which works today but won’t work once Stan starts using C++14 syntax. g++-4.9.3 is the floor for partial C++14 support.

Ah, the error I get is this:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /app/gcc5_new/include/c++/5.3.0/thread:35:0,
from /app/R/lib64/R/library/StanHeaders/include/stan/math/prim/mat/functor/map_rect_concurrent.hpp:10,
from /app/R/lib64/R/library/StanHeaders/include/stan/math/prim/mat/functor/map_rect.hpp:13,
from /app/R/lib64/R/library/StanHeaders/include/stan/math/prim/mat.hpp:262,
from /app/R/lib64/R/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
from /app/R/lib64/R/library/StanHeaders/include/stan/math.hpp:4,
from /app/R/lib64/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from filebda46593c6de.cpp:8:
/app/gcc5_new/include/c++/5.3.0/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c+
In addition: Warning message:
running command ‘/app/R/lib64/R/bin/R CMD SHLIB filebda46593c6de.cpp 2> filebda46593c6de.cpp.err.txt’ had status 1

I assumed that the -std=c+ suggestion was getting truncated, because that is not a valid specification, and was using -std=c++11.

OK, you should be fine going forward as long as the -std=c++14 or -std=c++1y flag is passed.