RStan fails to install on CentOS 7

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

Do you know what version of libstdc++ you have (c++ - Undefined reference to symbol throw_out_of_range - Stack Overflow)?

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

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

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.

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.

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

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:

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.

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

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
2 Likes

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!

2 Likes