# RStan fails to install on CentOS 7

**URL:** <https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957>\
**Category:** Interfaces\
**Tags:** linux, rstan\
**Created:** [June 15, 2020, 3:17pm UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957 "2020-06-15T15:17:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndrewKostandy](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@AndrewKostandy](https://discourse.mc-stan.org/u/AndrewKostandy)\
**Post date:** [June 15, 2020, 3:17pm UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/1 "2020-06-15T15:17:12Z")

</div>

### Summary:

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

### Description:

**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  
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

**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:

install.packages(“rstan”)

### 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/rstan.so’:  
/home/…/R/x86\_64-redhat-linux-gnu-library/3.6/00LOCK-rstan/00new/rstan/libs/rstan.so: 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

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [June 15, 2020, 3:39pm UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/2 "2020-06-15T15:39:33Z")

</div>

> [@AndrewKostandy](#):
>
> undefined symbol: \_ZSt24\_\_throw\_out\_of\_range\_fmtPKcz

Do you know what version of libstdc++ you have ([c++ - Undefined reference to symbol throw\_out\_of\_range - Stack Overflow](https://stackoverflow.com/questions/35649772/undefined-reference-to-symbol-throw-out-of-range))?

Do you mind checking if cmdstan will build on this computer? Here’s the 2.23 release: [https://github.com/stan-dev/cmdstan/releases/download/v2.23.0/cmdstan-2.23.0.tar.gz](https://github.com/stan-dev/cmdstan/releases/download/v2.23.0/cmdstan-2.23.0.tar.gz)

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).

---

<div class="post-metadata">

**Author:** ![AndrewKostandy](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@AndrewKostandy](https://discourse.mc-stan.org/u/AndrewKostandy)\
**Post date:** [June 15, 2020, 3:56pm UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/3 "2020-06-15T15:56:20Z")

</div>

Using:  
/sbin/ldconfig -p | grep stdc++

Returns:  
libstdc++.so.6 (libc6,x86-64) =\> /lib64/libstdc++.so.6

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

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [June 15, 2020, 4:42pm UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/4 "2020-06-15T16:42:27Z")

</div>

> [@AndrewKostandy](#):
>
> libstdc++.so.6 (libc6,x86-64) =\> /lib64/libstdc++.so.6

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 `libstdc++.so` 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.

---

<div class="post-metadata">

**Author:** ![AndrewKostandy](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@AndrewKostandy](https://discourse.mc-stan.org/u/AndrewKostandy)\
**Post date:** [June 17, 2020, 1:07am UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/6 "2020-06-17T01:07:27Z")

</div>

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.

### Output:

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

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [June 17, 2020, 1:14am UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/7 "2020-06-17T01:14:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AndrewKostandy](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@AndrewKostandy](https://discourse.mc-stan.org/u/AndrewKostandy)\
**Post date:** [June 17, 2020, 1:26am UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/8 "2020-06-17T01:26:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [June 17, 2020, 1:29am UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/9 "2020-06-17T01:29:17Z")

</div>

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

Can you do a:

```
locate libstdc++.so

```

on your computer?

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

Then add something like:

```
LDFLAGS=-L/usr/lib/gcc/x86_64-linux-gnu/7

```

To your `.R/Makevars` pointing to the folder containing the `libstdc++.so` that matches your gcc.

---

<div class="post-metadata">

**Author:** ![AndrewKostandy](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@AndrewKostandy](https://discourse.mc-stan.org/u/AndrewKostandy)\
**Post date:** [June 17, 2020, 2:05am UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/10 "2020-06-17T02:05:53Z")

</div>

Running:

```
locate libstdc++.so

```

Returns:

/opt/bmc/bladelogic/NSH/Ovaldi/libstdc++.so.6  
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86\_64-redhat-linux/7/libstdc++.so  
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86\_64-redhat-linux/7/32/libstdc++.so  
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.19-gdb.py  
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.19-gdb.pyc  
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.19-gdb.pyo  
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.py  
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyc  
/opt/rh/devtoolset-7/root/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyo  
/usr/lib/gcc/x86\_64-redhat-linux/4.8.2/libstdc++.so  
/usr/lib/gcc/x86\_64-redhat-linux/4.8.2/32/libstdc++.so  
/usr/lib64/libstdc++.so.6  
/usr/lib64/libstdc++.so.6.0.19  
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.py  
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyc  
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyo

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

```
LDFLAGS=/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7

LDFLAGS=-L/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7

LDFLAGS=/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libstdc++.so

```

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/libstdc++.so.6  
collect2: error: ld returned 1 exit status  
make: \*\*\* [/usr/share/R/make/shlib.mk:6: rstan.so] 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…)

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [June 17, 2020, 1:39pm UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/11 "2020-06-17T13:39:45Z")

</div>

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):

```
CC=gcc
CXX=g++
CXX11=g++
CXX14=g++
CFLAGS=-g -O0
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
LDFLAGS=-g

```

---

<div class="post-metadata">

**Author:** ![AndrewKostandy](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@AndrewKostandy](https://discourse.mc-stan.org/u/AndrewKostandy)\
**Post date:** [June 17, 2020, 2:45pm UTC](https://discourse.mc-stan.org/t/rstan-fails-to-install-on-centos-7/15957/12 "2020-06-17T14:45:42Z")

</div>

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  
LDFLAGS=-L/opt/rh/devtoolset-7/root/usr/lib/gcc/x86\_64-redhat-linux/7

Thanks a lot for your help, Ben!
