Rstan package compiler error (RHEL 7 : gcc5.3.0)

Operating System: RHEL 7
Interface Version: rstan 2.18.1
Compiler/Toolkit: gcc 5.3.0

My Makevars.R only contains CXX14=gcc at the moment.

StanHeaders successfully compiles and installs using its -std=gnu99. rstan throws errors when linking against it during its own compilation process.
image

Anyone see a solution?

That should be CXX14 = g++

My mistake, typing too late. It did/does contain CXX14 = g++

Why are you using gnu99? That’s a GNU dialect of a C standard, not a C++ standard.

The error that you are getting indicates that g++ is using an older C++ standard, probably C++98, rather than C++14. You probably need something like -std=c++1y. If gcc 5.3 is too old, you might want to get the Red Hat Developer Toolset. Another alternative is to use the R packages from Anaconda, which pulls in an up-to-date compiler as well.

1 Like

Sorry, I was referring to messages like this that I see when I install StanHeaders.
image

Good call on the -std flag. Adding -std=c++14 does seem to have fix the proximate error.

I would normally attempt to use a precompiled version, but unfortunately I do have to compile from source in this case.

I also needed to add -fPIC, but then everything compiled. In summary, my minimal Makevars.R was:

CXX14 = g++
CXX14STD = -std=c++14 -fPIC

Thanks for the help!

Edit/addendum/related:
it strikes me as a bit odd that the linux toolchain here has -std=c++11

I am not seeing that. But it should be -std=c++1y or -std=c++14 on Mac / Linux.

It is this one. I think it actually might be okay, in that I successfully installed rstan on another server using this makevars file since my last post:

Thanks. I just eliminated the -std=c++11. Basically, the Makevars file should just define CXX14 and CXX14FLAGS and let the regular R build process figure out whether it needs to say -std=c++1y or -std=c++14.

Understood! Thanks for the help.