Compile error

Hi stan users,

I installed the rstan 2.18.2 following the instructions. However, there are always errors when compiling.

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from C:/Program Files/R/R-3.5.3/library/BH/include/boost/random/detail/integer_log2.hpp:19:0,
from C:/Program Files/R/R-3.5.3/library/BH/include/boost/random/detail/int_float_pair.hpp:26,
from C:/Program Files/R/R-3.5.3/library/BH/include/boost/random/exponential_distribution.hpp:27,
from C:/Program Files/R/R-3.5.3/library/BH/include/boost/random/gamma_distribution.hpp:25,
from C:/Program Files/R/R-3.5.3/library/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_rng.hpp:5,
from C:/Program Files/R/R-3.5.3/library/StanHeaders/include/stan/math/prim/mat.hpp:276,
from C:/Program Files/R/R-3.5.3/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
from C:/Program Files/R/R-3.5.3/library/StanHeaders/include/stan/math.hpp:4,
from C:/Program Files/R/R-3.5.3/library/StanHeaders
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-35~1.3/bin/x64/R CMD SHLIB file15cc6e2f1671.cpp 2> file15cc6e2f1671.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

How can I fix this problem?

Thanks.

If you do something like

stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'
mod <- stan_model(model_code = stancode, verbose = TRUE)

what is the string surrounding the word error: (with the colon) in the output?

Thanks for your reply. I removed the following steps and it can run successfully.
Sys.setenv(LOCAL_CPPFLAGS = ‘-march=native’)
options(mc.cores = parallel::detectCores())

I have the exact same error under Red Hat 7. The error message when running the suggested code is:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /ext/home/ericiulescua/R/x86_64-redhat-linux-gnu-library/3.5/BH/include/boost/random/detail/integer_log2.hpp:19:0,
from /ext/home/ericiulescua/R/x86_64-redhat-linux-gnu-library/3.5/BH/include/boost/random/detail/int_float_pair.hpp:26,
from /ext/home/ericiulescua/R/x86_64-redhat-linux-gnu-library/3.5/BH/include/boost/random/exponential_distribution.hpp:27,
from /ext/home/ericiulescua/R/x86_64-redhat-linux-gnu-library/3.5/BH/include/boost/random/gamma_distribution.hpp:25,
from /ext/home/ericiulescua/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_rng.hpp:5,
from /ext/home/ericiulescua/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat.hpp:292,
from /ext/home/ericiulescua/R/x86_64-redhat-linux-gnu-library/3.5/StanHeaders/include/stan/m

It can’t find the headers. I have the following session info:

R version 3.5.2 (2018-12-20)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: OpenShift Enterprise

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

other attached packages:
[1] rstan_2.18.2 StanHeaders_2.18.1-10 ggplot2_3.2.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 rstudioapi_0.10 magrittr_1.5 tidyselect_0.2.5
[5] munsell_0.5.0 colorspace_1.4-1 R6_2.4.0 rlang_0.4.0
[9] dplyr_0.8.1 tools_3.5.2 parallel_3.5.2 pkgbuild_1.0.3
[13] grid_3.5.2 gtable_0.3.0 loo_2.1.0 cli_1.1.0
[17] withr_2.1.2 matrixStats_0.54.0 yaml_2.2.0 lazyeval_0.2.2
[21] assertthat_0.2.1 tibble_2.1.3 crayon_1.3.4 processx_3.4.0
[25] gridExtra_2.3 callr_3.3.0 purrr_0.3.2 ps_1.3.0
[29] inline_0.3.15 glue_1.3.1 compiler_3.5.2 pillar_1.4.2
[33] prettyunits_1.0.2 scales_1.0.0 stats4_3.5.2 pkgconfig_2.0.2

Any new on this topic? I have the same problem in RH7

I think this has been made into a GitHub issue here: https://github.com/stan-dev/rstan/issues/666

We need a verbose = TRUE when you call stan or sampling to see what it tries to compile and why it fails to find the libraries correctly.

Here in early 2021, the solution for me was to update to the most recent version of R. Details on that can be found here Install/Update R & RStudio