Error Install rstan in CentOS: C++17 standard requested but CXX17 is not defined

I am trying to install rstan in Centos.

I am getting the following error:

Error: C++17 standard requested but CXX17 is not defined

My g++ version if relevant is the following:

g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 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.

My OS Details:

Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:        7.9.2009
Codename:       Core

Running the following does not seem to work:

mkdir -p ~/.R
echo 'CXX17 = g++-7 -std=gnu++17 -fPIC' > ~/.R/Makevars

Hi, @Abhishek_R and sorry we didn’t respond sooner.

You’ll need to

  1. Get a newer version of GCC than 4.8.5.

  2. Define CXX17 to be that newer version you install.

  3. I’m pretty sure you want std=c++17 rather than std+gnu++17. See: