RStan fails to install on CentOS 7


I’m am unable to install the rstan package on a linux machine running CentOS 7.


Here’s my session info:

R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Here are the contents of my /.R/Makevars file:

CXX14 = /opt/rh/devtoolset-7/root/usr/bin/gcc -std=c++1y
CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -fPIC
CXX14FLAGS+=-flto -Wno-unused-local-typedefs

I have updated the PATH using: (I replaced my user id below with …)

Sys.setenv(PATH = “/opt/rh/devtoolset-7/root/usr/bin:/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/home/…/.local/bin:/home/…/bin:/home/…/.local/bin:/home/…/bin:/home/…/.local/bin:/home/…/bin”)

Running system2(“gcc”,"–version") in RStudio returns:

gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Copyright © 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

I have StanHeaders 2.21.0-5 installed.

I have also done the below step:

export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/usr/local/lib64:/usr/lib64

Reproducible Steps:


Current Output:

long output that ends with:

*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘rstan’ in dyn.load(file, DLLpath = DLLpath, …):
unable to load shared object ‘/home/…/R/x86_64-redhat-linux-gnu-library/3.6/00LOCK-rstan/00new/rstan/libs/’:
/home/…/R/x86_64-redhat-linux-gnu-library/3.6/00LOCK-rstan/00new/rstan/libs/ undefined symbol: _ZSt24__throw_out_of_range_fmtPKcz
Error: loading failed
Execution halted
ERROR: loading failed
removing ‘/home/…/R/x86_64-redhat-linux-gnu-library/3.6/rstan’
Warning in install.packages :
installation of package ‘rstan’ had non-zero exit status

Do you know what version of libstdc++ you have (

Do you mind checking if cmdstan will build on this computer? Here’s the 2.23 release:

Unzip that, go inside, and type:

make examples/bernoulli/bernoulli

And then wait and see if it builds (if it succeeds you should be able to type ./examples/bernoulli/bernoulli and get a help message back).

/sbin/ldconfig -p | grep stdc++

Returns: (libc6,x86-64) => /lib64/

In the mean time, I will check if I can try building cmdstan on this computer.

Haha, I guess that’s what I asked for but I’m not familiar enough to interpret it.

I guess my point was in that thread (and other unrelated software where this is discussed) it’s talked about like an issue with the libstdc++ library.

That made me think maybe the wrong library is getting linked or something, but I don’t quite know how to diagnose this.

For instance, on my computer I have gcc 7.5.0 and there’s a in /usr/lib/gcc/x86_64-linux-gnu/7/ (which has the gcc version in it).

But first I’m curious if the cmdstan itself builds. Then we can maybe know if this is a system thing or an R configuration thing.

Hi Ben

I have done the make examples/bernoulli/bernoulli step and it seemed to work successfully.
The ./examples/bernoulli/bernoulli step returns the output below.


Usage: ./examples/bernoulli/bernoulli <subarg1_1> … <subarg1_m> … <arg_n> <subarg_n_1> … <subarg_n_m>

Begin by selecting amongst the following inference methods and diagnostics,
sample Bayesian inference with Markov Chain Monte Carlo
optimize Point estimation
variational Variational inference
diagnose Model diagnostics
generate_quantities Generate quantities of interest

Or see help information with
help Prints help
help-all Prints entire argument tree

Additional configuration available by specifying
id Unique process identifier
data Input data options
init Initialization method: “x” initializes randomly between [-x, x], “0” initializes to 0, anything else identifies a file of values
random Random number configuration
output File output options

See ./examples/bernoulli/bernoulli [ help | help-all ] for details on individual arguments.

Failed to parse arguments, terminating Stan

1 Like

Hmm, alright if this worked then I would try making your .R/Makevars blank and not doing anything with the Sys.setenv. Apparently your system can compile cmdstan, so we should start with a configuration as generic as possible.

It appears I have multiple gcc versions on my system.

I need to use the command “scl enable devtoolset-7 bash” in terminal so “gcc --version” gives me 7.3.1 on terminal, otherwise I get 4.8.5.

Similarly in RStudio, “system2(“gcc”,”–version")" gives me version 4.8.5 unless I run the Sys.setenv(…) command before it. Then it gives me 7.3.1.

In my Makevars file the " /opt/rh/devtoolset-7/root/usr/bin/gcc" part refers to the gcc 7.3.1 path.

Aaah, okay, and so we probably need to do something about this for libstdc++ as well.

Can you do a:


on your computer?

Edit: The locate is to find a suitable libstdc++

Then add something like:


To your .R/Makevars pointing to the folder containing the that matches your gcc.





I tried adding the following (separately) to the Makevars and then install rstan but the installation failed all three times.




In the first and third case I got the error:

/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: cannot find /usr/lib/
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/make/] Error 1
ERROR: compilation failed for package ‘rstan’

While in the second case I got the original error (load failed in dyn.load…throw out of range…)

Oh I think the second is correct (the one with the -L). Hmmm. Do you have more of the error message before that? Can you post the full thing (maybe as an attached .txt file)?

The next line I’m looking at is this:

CXX14 = /opt/rh/devtoolset-7/root/usr/bin/gcc -std=c++1y

Can you do:

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

I know clang is picky about the difference in clang and clang++ (and it comes down to libraries).

One time I did some stuff with another compiler and I ended up having to change all the various optional compilers in my .R/Makevars.

It ended up looking something like (for the thing I was doing):

CXXFLAGS=-g -O0 -Wno-deprecated-declarations -Wno-ignored-attributes
CXX11FLAGS=-g -O0 -Wno-deprecated-declarations -Wno-ignored-attributes
CXX14FLAGS=-g -O0 -Wno-deprecated-declarations -Wno-ignored-attributes

Your suggestion worked! RStan installed and loaded successfully.

This is my final Makevars file:

CXX14 = /opt/rh/devtoolset-7/root/usr/bin/g++
CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -fPIC
CXX14FLAGS+=-flto -Wno-unused-local-typedefs

Thanks a lot for your help, Ben!