Compilation ERROR, function(s)/method(s) not created

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file59ec70b01ab1.cpp:8:39: fatal error: stan/model/model_header.hpp: No such file or directory
#include <stan/model/model_header.hpp>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file59ec70b01ab1.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB file59ec70b01ab1.cpp 2> file59ec70b01ab1.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

I have read most related threads before posting here but I have not been able to resolve the issue. Here is my sessionInfo()

sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252

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

other attached packages:
[1] BH_1.69.0-1 RcppEigen_0.3.3.5.0 rstan_2.18.2 StanHeaders_2.18.1-10 SDMTools_1.1-221.1 tibble_2.1.3
[7] readxl_1.3.1 readr_1.3.1 tidyr_0.8.3 ggplot2_3.2.0 dplyr_0.8.3

loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 pillar_1.4.2 compiler_3.6.0 cellranger_1.1.0 prettyunits_1.0.2 R.methodsS3_1.7.1 R.utils_2.9.0
[8] tools_3.6.0 packrat_0.5.0 pkgbuild_1.0.3 lattice_0.20-38 gtable_0.3.0 pkgconfig_2.0.2 rlang_0.4.0
[15] Matrix_1.2-17 cli_1.1.0 rstudioapi_0.10 parallel_3.6.0 loo_2.1.0 gridExtra_2.3 withr_2.1.2
[22] hms_0.4.2 stats4_3.6.0 grid_3.6.0 tidyselect_0.2.5 glue_1.3.1 inline_0.3.15 R6_2.4.0
[29] rematch_1.0.1 processx_3.4.0 purrr_0.3.2 callr_3.3.0 magrittr_1.5 matrixStats_0.54.0 ps_1.3.0
[36] scales_1.0.0 rsconnect_0.8.13 assertthat_0.2.1 colorspace_1.4-1 lazyeval_0.2.2 munsell_0.5.0 crayon_1.3.4
[43] R.oo_1.22.0

The errors look very similar to the ones in this thread: https://github.com/stan-dev/rstan/issues/561 . I think the conclusion of people there is to just reinstall everything. Unfortunately doesn’t look like any specific debugging of it.

Just do

install.packages("https://win-builder.r-project.org/rTkumr03G8UM/rstan_2.19.1.zip", repos = NULL)

and then get 2.19.2 from CRAN when the Windows binary gets built.

2 Likes

Thanks Ben and Ben,

I was able to resolve the issue after I decided to install everything in C:\ rather than in a network drive where my home folder is located.

regards,
vishy

1 Like

I’m having the same issue on Linux. However when i try to reinstall rstan I get a bunch of errors possibly related to the StanHeaders package. I do have the latest version of stanheaders installed.

> install.packages("rstan")
Installing package into ‘/home/awblack/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/rstan_2.19.2.tar.gz'
Content type 'application/x-gzip' length 909934 bytes (888 KB)
==================================================
downloaded 888 KB

* installing *source* package ‘rstan’ ...
** package ‘rstan’ successfully unpacked and MD5 sums checked
** libs


g++   -I"/opt/R/3.5.1/lib64/R/include" -DNDEBUG -I"../inst/include" -I"." -I"/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/opt/R/3.5.1/lib64/R/library/Rcpp/include" -I"/opt/R/3.5.1/lib64/R/library/RcppEigen/include" -I"/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/BH/include" -I"/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include" -I/usr/local/include     -O3 -c chains.cpp -o chains.o
In file included from chains.cpp:19:0:
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp: In function ‘typename boost::math::tools::promote_args<T>::type stan::math::mean(const std::vector<T>&)’:
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:63: error: an array reference cannot appear in a constant-expression
   Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
                                                               ^
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:63: error: ‘&’ cannot appear in a constant-expression
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:68: error: ‘.’ cannot appear in a constant-expression
   Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
                                                                    ^
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:73: error: a function call cannot appear in a constant-expression
   Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
                                                                         ^
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:74: error: a function call cannot appear in a constant-expression
   Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
                                                                          ^
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:74: error: template argument 3 is invalid
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:74: error: template argument 4 is invalid
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:74: error: template argument 6 is invalid
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:27: error: template argument 1 is invalid
   Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
                           ^
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:25:10: error: ‘m’ was not declared in this scope
   return m.mean();
          ^
In file included from /home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/mat/fun/sum.hpp:5:0,
                 from chains.cpp:20:
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/arr/fun/sum.hpp: In function ‘T stan::math::sum(const std::vector<T>&)’:
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/StanHeaders/include/stan/math/prim/arr/fun/sum.hpp:20:48: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
   return std::accumulate(xs.begin(), xs.end(), T{0});
                                                ^
In file included from /home/awblack/R/x86_64-pc-linux-gnu-library/3.5/BH/include/boost/random/detail/integer_log2.hpp:19:0,
                 from /home/awblack/R/x86_64-pc-linux-gnu-library/3.5/BH/include/boost/random/detail/large_arithmetic.hpp:19,
                 from /home/awblack/R/x86_64-pc-linux-gnu-library/3.5/BH/include/boost/random/detail/const_mod.hpp:23,
                 from /home/awblack/R/x86_64-pc-linux-gnu-library/3.5/BH/include/boost/random/linear_congruential.hpp:30,
                 from /home/awblack/R/x86_64-pc-linux-gnu-library/3.5/BH/include/boost/random/additive_combine.hpp:27,
                 from chains.cpp:29:
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/BH/include/boost/pending/integer_log2.hpp: At global scope:
/home/awblack/R/x86_64-pc-linux-gnu-library/3.5/BH/include/boost/pending/integer_log2.hpp:7:89: note: #pragma message: This header is deprecated. Use <boost/integer/integer_log2.hpp> instead.
 BOOST_HEADER_DEPRECATED("<boost/integer/integer_log2.hpp>");
                                                                                         ^
make: *** [chains.o] Error 1
ERROR: compilation failed for package ‘rstan’
* removing ‘/home/awblack/R/x86_64-pc-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/RtmpCVpQMr/downloaded_packages’

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)

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

other attached packages:
[1] bayesplot_1.7.0       lubridate_1.7.4       dplyr_0.8.3           rstan_2.17.3          StanHeaders_2.18.1-10 ggplot2_3.2.0        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1       pillar_1.4.2     compiler_3.5.1   plyr_1.8.4       tools_3.5.1      digest_0.6.20    tibble_2.1.3     gtable_0.3.0     pkgconfig_2.0.2  rlang_0.4.0      rstudioapi_0.9.0
[12] yaml_2.2.0       xfun_0.8         gridExtra_2.3    withr_2.1.2      stringr_1.4.0    knitr_1.23       stats4_3.5.1     grid_3.5.1       tidyselect_0.2.5 glue_1.3.1       inline_0.3.15   
[23] R6_2.4.0         purrr_0.3.2      magrittr_1.5     scales_1.0.0     ggridges_0.5.1   assertthat_0.2.1 colorspace_1.4-0 labeling_0.3     stringi_1.4.3    lazyeval_0.2.2   munsell_0.5.0   
[34] crayon_1.3.4   

What g++ version are you using? I suspect you need to supply the C++14 flags.

gcc version 4.8.5 20150623

I changed my .R/Makevars file to

CXX14FLAGS=-O3 -march=native -mtune=native -fPIC -std=c++1y
CXX14=g++

and manually added the -std=c++1y flag.
rstan compiled and installed successfully.

I found some additional details here:
https://discourse.mc-stan.org/t/installing-rstan-in-rhel-with-std-c-11-flag/6217

Thanks!

You really need to upgrade to a more recent compiler. I don’t think 4.8.5 actually supports enough of the C++14 standard (although it tolerates the flag).

The latest version available through the redhat repository is 4.9.3 I think. Hopefully that will be good enough.

Also even thought I successfully installed rstan I’m still getting the “function(s)/method(s) not created!” error message when I try to compile a stan program. Hopefully updating the compiler to 4.9 will fix my problems.

As an aside – just want to say thanks for making the Stancon2018 videos available on youtube. It would be awesome if you all recorded stancon2019 as well. I’ve learned a lot from those recordings.

Red Hat does make available its Developer Toolset, which has much more up-to-date versions of GCC.

1 Like