rstan C++14 error while installing (centos)
Asked Answered
M

5

9

while installing rstan getting following error:

Error in .shlib_internal(args) :
C++14 standard requested but CXX14 is not defined

from research got to know that C++14 compiler should be available. How to install the same while configuring R. Using the below command to configure R

./configure --with-readline=no --with-x=no

and installing

yum install -y devtoolset-6

but still not able to update C++14 and rstan gives the error

Default C++ compiler:      g++   -g -O2
C++98 compiler:            g++  -g -O2
C++11 compiler:            g++ -std=gnu++11 -g -O2
C++14 compiler:            g++   -g -O2  
C++17 compiler:              
Fortran 90/95 compiler:    gfortran -g -O2
Obj-C compiler: 

setup.sh

 yum -y update
 yum install -y centos-release-scl
 yum install -y devtoolset-6
 yum install -y devtoolset-6-gcc-gfortran
 scl enable devtoolset-6 bash
 scl enable devtoolset-6-gcc-gfortran bash
 mkdir packages
 cd packages
 wget -qO- 
 https://downloads.sourceforge.net/project/libpng/zlib/1.2.8/zlib- 
 1.2.8.tar.gz | tar zvx
 cd zlib-1.2.8
 ./configure
 make
 make install
 cd ..
 wget -qO- http://downloads.sourceforge.net/pcre/pcre-8.35.tar.gz | 
 tar xzv
 cd pcre-8.35
 ./configure
 make
 make install
 cd ..
 wget -qO- http://tukaani.org/xz/xz-5.2.2.tar.gz | tar xzv
 cd xz-5.2.2
 ./configure
 make
 make install
 cd ..
 wget -qO- https://curl.haxx.se/download/curl-7.47.1.tar.gz | tar xzv
 cd curl-7.47.1
 ./configure
 make
 make install
 cd ..


 wget -qO- https://cran.r-project.org/src/base/R-3/R-3.4.4.tar.gz | 
 tar xzv
 cd R-3.4.4
 ./configure --with-readline=no --with-x=no --prefix=/packages/R-3.4.4 
 F77=gfortran
 make
 make install
Mingy answered 30/11, 2018 at 6:8 Comment(0)
A
13

I also got this problem, here I record how to solve it.

The key point is installing proper g++ and configure it.

Firstly, install g++ Version >= 5 as https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Linux said:

Using RStan requires either g++ version 4.9 and up

Here I am installing g++8 (You can change the version as your wish):

Run

$ sudo yum install centos-release-scl
$ sudo yum install devtoolset-8-gcc*

Now you have an alternative g++ along with default g++ in your OS.

You can enable this and check the version:

$ scl enable devtoolset-8 bash
$ gcc --version
$ g++ --version

Find its location:

$ which g++
/opt/rh/devtoolset-8/root/usr/bin/g++

Next, you need to configure ~/.R/Makevars, put the following content to it either using vim (or other editors):

CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14=/opt/rh/devtoolset-8/root/usr/bin/g++

Or using R commands:

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "Makevars")
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native -mtune=native -fPIC",
    "CXX14=/opt/rh/devtoolset-8/root/usr/bin/g++", # or clang++ but you may need a version postfix
    file = M, sep = "\n", append = TRUE)

NOTE: these R commands are copied from https://github.com/stan-dev/rstan/wiki/Configuring-C-Toolchain-for-Linux but CXX14 flag is modified according to the location above.

Now, you can install rstan package now:

install.packages("rstan")

Hope this helps.


PS: R users can use this approach to modify the compiler flags in a similar way.

Auvergne answered 20/9, 2019 at 8:0 Comment(3)
I believe this link is no longer functioning.Gregorio
@Gregorio Thanks for pointing out, I have updated.Auvergne
Is the path to g++ only requirement? devtoolset has own versions of make or valgrind. I was using scripts with all toolset enable but your configuration is very convenient.Butterball
A
3

This is what worked for me:

CXX_STD = CXX14

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

CXX14FLAGS = -O3 -fPIC -Wno-unused-variable -Wno-unused-function -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION

Amelita answered 13/3, 2019 at 16:8 Comment(1)
Which file should this write to?Auvergne
P
1

You don't need to recompile R but you do need at least g++-4.9 (or clang++-3.4) and to define CXX14 = g++ in your ~/.R/Makevars configuration file. In addition, you usually need CXX14FLAGS = -fPIC and would be well advised to have CXX14FLAGS = -O3 -mtune = native -march = native -fPIC. There is a wiki page for all this.

Paderna answered 30/11, 2018 at 15:34 Comment(0)
M
1

did the following changes and now it's working fine. Need to define gcc PATH and used yum install -y devtoolset-6 for R-3.4.4. Thank you for help

yum install -y centos-release-scl
yum install -y devtoolset-6
yum install -y bzip2-devel
source scl_source enable devtoolset-6

also added the Path to gcc in build.sh 

export PATH=/opt/rh/devtoolset-6/root/bin:$PATH
Mingy answered 5/12, 2018 at 7:18 Comment(0)
G
0

I had the same problem. Here is my solution in case it helps others.

On CentOS 7, I:

  1. installed V8 headers and shared library from here: https://pkgs.org/download/v8-devel 41 (EPEL_x86_64)

  2. bumped gcc from version 4 to 9.3.1

In R, I:

  1. removed rstan and StanHeaders

  2. installed rstan and StanHeaders in a fresh R session

Posted discussion on Stan Forum here: https://discourse.mc-stan.org/t/problem-installing-rstan-2-21-using-r-4-0-1-on-centos-7/17784/9

Gregorio answered 29/12, 2020 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.