Installing rstan on RHEL7

Hi, I received the following error message when attempting to build and install rstan from source under RHEL 7.2:

/usr/lib64/R/etc/Makeconf:166: recipe for target ‘lang__grammars__expression_grammar_inst.o’ failed
make: *** [lang__grammars__expression_grammar_inst.o] Error 1
ERROR: compilation failed for package ‘rstan’

  • removing ‘/home/savitskyt/R/x86_64-redhat-linux-gnu-library/3.4/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

My system information is:

R version 3.4.0 (2017-04-21)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0 coda_0.19-1 grid_3.4.0 lattice_0.20-35
[6] rjags_4-6

Thanks for your help,

Terrance.

I write to verify that this fix worked for me. Thanks for your help.

There are 2 lines with CXX14FLAGS, and I add “DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION” to both of them, but the error still persists. Could you explain more?
Thank you.

CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -fPIC -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION
CXX14 = g++

CXX14FLAGS+=-flto -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION

I don’t think you should need -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION anymore. What is the error message you are seeing?

The server system: CentOS 7.5

I followed https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Mac-or-Linux

cat(

  • "\nCXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -fPIC",
    
  • "CXX14 = g++", # could also you clang++ but your compiler may have a version number postfix
    
  • file = MAKEVARS, 
    
  • sep = "\n", 
    
  • append = TRUE
    
  • )
    cat("\nCXX14FLAGS+=-flto -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations",
  • file = MAKEVARS, sep = "\n", append = TRUE)
    

cat(readLines(MAKEVARS), sep = “\n”)

This outputs:

CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -fPIC
CXX14 = g++

CXX14FLAGS+=-flto -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations

I tried as you say, not to add

-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION

and then both “pkgbuild::has_build_tools(debug = TRUE)” and "fx <- inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’
return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
’ )

fx( 2L, 5 )" passed.

Then

install.packages(c(“Rcpp”, “rstan”), type = “source”)

which has a long output and I copy the final part which I think important. Please tell me if you wanna see more.

At global scope:
cc1plus: warning: unrecognized command line option “-Wno-ignored-attributes” [enabled by default]
make: *** [lang__ast_def.o] Error 1
ERROR: compilation failed for package ‘rstan’

  • removing ‘/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

The downloaded source packages are in
‘/tmp/RtmpE6CZuG/downloaded_packages’

Thank you.

Can you copy the part that has the string error: (with the trailing colon)?

The total output has 90 “error:”.
I just copy the final 2 and the rest is attached.
Thank you.

/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/function_signatures.h:1365:24: error: range-based ‘for’ loops are not allowed in C++98 mode
for (const auto& u : all_vector_types) {
^
/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/function_signatures.h:1366:57: error: no matching function for call to ‘stan::lang::function_signatures::rng_return_type(const int&, const int&)’
add(“weibull_rng”, rng_return_type<double_type>(t, u), t, u);

rstan installing error on Red 20181029.pdf (162.4 KB)

You may need to call

Sys.setenv(USE_CXX14 = 1)

once before installing.

I did that.
The same error comes:

In file included from /home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast.hpp:65:0,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast_def.cpp:7,
from lang__ast_def.cpp:18:
/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures.hpp:306:17: note: template stan::lang::expr_type stan::lang::function_signatures::rng_return_type(const stan::lang::expr_type&, const stan::lang::expr_type&, const stan::lang::expr_type&)
expr_type rng_return_type(const expr_type& t,
^
/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures.hpp:306:17: note: template argument deduction/substitution failed:
In file included from /home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures_def.hpp:486:0,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/ast_def.cpp:119,
from lang__ast_def.cpp:18:
/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/src/stan/lang/function_signatures.h:1366:57: note: cannot convert ‘t’ (type ‘const int’) to type ‘const stan::lang::expr_type&’
add(“weibull_rng”, rng_return_type<double_type>(t, u), t, u);
^
At global scope:
cc1plus: warning: unrecognized command line option “-Wno-ignored-attributes” [enabled by default]
make: *** [lang__ast_def.o] Error 1
ERROR: compilation failed for package ‘rstan’

  • removing ‘/home/changy/R/x86_64-redhat-linux-gnu-library/3.5/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

The downloaded source packages are in
‘/tmp/RtmpAmotUi/downloaded_packages’

Somehow, it is not realizing that it is supposed to be using C++14. In a shell, what comes back after you execute R CMD config CXX14 ?

Also, what does g++ --version say?

Thank you for your quick response.

[root@euca-128-84-10-160 ~]# R CMD config CXX14

g++

[root@euca-128-84-10-160 ~]# g++ --version

g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)

Copyright © 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.

Technically, g++-4.8 is not sufficient because it does not implement any of the C++14 standard, although it does accept the -std=c++1y flag. On the other hand, Stan 2.18 technically isn’t using any of the C++14 syntax. It will probably work if you set

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

but you should look into getting a newer version of g++ or clang++ from the RHEL repos.

I tried “yum install gcc” as in https://stackoverflow.com/questions/47175706/how-to-install-gcc-4-9-2-on-rhel-7-4 , but with the following error. yum install others also have the same issue. Could you recommend a repo (url) for new g++?
Thank you.

Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 18 kB 00:00:00
Could not retrieve mirrorlist http://mirrors.eucalyptus.com/mirrors?product=euca2ools&distro=rhel&releasever=7&basearch=x86_64&version=3.4 error was
14: curl#6 - “Could not resolve host: mirrors.eucalyptus.com; Unknown error”

One of the configured repositories failed (Unknown),
and yum doesn’t have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work “fix” this:

 1. Contact the upstream for the repository and get them to fix the problem.

 2. Reconfigure the baseurl/etc. for the repository, to point to a working
    upstream. This is most often useful if you are using a newer
    distribution release than is supported by the repository (and the
    packages for the previous distribution release still work).

 3. Run the command with the repository temporarily disabled
        yum --disablerepo=<repoid> ...

 4. Disable the repository permanently, so yum won't use it by default. Yum
    will then just ignore the repository until you permanently enable it
    again or use --enablerepo for temporary usage:

        yum-config-manager --disable <repoid>
    or
        subscription-manager repos --disable=<repoid>

 5. Configure the failing repository to be skipped, if it is unavailable.
    Note that yum will try to contact the repo. when it runs most commands,
    so will have to try and fail each time (and thus. yum will be be much
    slower). If it is a very temporary problem though, this is often a nice
    compromise:

        yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: euca2ools/7/x86_64

I think you need to look into the Red Hat Developer Toolset
https://access.redhat.com/documentation/en-us/red_hat_developer_toolset/8-beta/
but really if you have RHEL you usually have a system administrator who knows what additional repositories are out there and which are permitted under support constracts and so forth.

I followed the following advice from University service, and now the rstan is installed.

Please make sure devtoolset-7 (not Red Had Developer Toolkit) is installed:

sudo yum install centos-release-scl
sudo yum install devtoolset-7

It must also be enabled in your shell so it becomes the default g++ compiler:

scl enable devtoolset-7 bash

However, when I run

GMM.stan.model=stan_model(file=“GMMdesign20181030_standardize_noZ_redundant_1level.stan”,model_name = “GMM_stan”)

with the stan file
GMMdesign20181030_standardize_noZ_redundant_1level.stan (1.8 KB)

the following error comes:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /usr/include/c++/4.8.2/thread:35:0,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/functor/map_rect_concurrent.hpp:10,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/functor/map_rect.hpp:13,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat.hpp:262,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
from /usr/lib64/R/library/StanHeaders/include/stan/math.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from file6202730a0d5.cpp:8:
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler op
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/usr/lib64/R/bin/R CMD SHLIB file6202730a0d5.cpp 2> file6202730a0d5.cpp.err.txt’ had status 1

Try adding CXX14FLAGS+= -std=c++11 to your makefile. I am short on explanations, but our systems are very similar and specifying std fixes the same error for me.

As for where I got it, the error tells you to enable -std=c++11

It is not recognizing your newer C++ compiler. Check the step where you enable it to be the default compiler or perhaps specify g++-7 or whatever its version number is.