Compilation Error with StanHeaders: no such file or directory

Summary:

Compilation error when running the main stan function. I receive an error that several files used by StanHeaders cannot be found (even when they exist).

Description:

I am a new Stan user and had no problem with installation of all dependencies. However, when I try to run a simple “Hello, world” type example (found here), I receive a compilation error that I put under the current output section.

I have messed with changing the Makevars.win file and tried several others alternatives I found within the issues requests, but to no avail. From the output, I believe the issue to be related somehow to the file name having a space, but Program Files should be the standard in all of Windows file naming, how would this be an issue?

Reproducible Steps:

remove(list = ls())
library(rstan)

hello.stan <- 'data {
  int<lower=0> N;
  vector[N] y;
}
parameters {
  real mu;
  real<lower=0> sigma;
}
model {
  y ~ normal(mu, sigma);
}
'

N <- 100
y <- rnorm(N, mean = 5, sd = 10)
stanfit <- stan(model_name = hello.stan, data = list(N, y))

Current Output:

Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created!
g++.exe: error: Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
g++.exe: error: Files/R/R-3.6.2/library/StanHeaders/include: No such file or directory
g++.exe: error: Files/R/R-3.6.2/library/RcppEigen/include: No such file or directory
make: *** [C:/PROGRA~1/R/R-3.6.2/etc/x64/Makeconf:215: file4f647a08385b.o] Error 1

RStan Version:

2.19.2

R Version:

R version 3.6.2 (2019-12-12)

Operating System:

Windows 10 Pro, 64 Bit, Version 1809

This was an issue with the StanHeaders version getting ahead of the RStan version on CRAN, since some of the file paths changed between the two versions. It’s since been reverted but CRAN is still providing the 2.21 binaries. To fix this you need to reinstall the packages from source:

install.packages(c("rstan","StanHeaders"),type="source")
2 Likes

I am having the same issue on a Windows 7 OS (bootcamp on Mac), with R 3.6.2. I have tried your suggestions, and it doesn’t seem to help. I am getting the exact same errors as smonto2.

Does anyone have any other thoughts?

Do you get the same error about the Eigen.hpp file?:

StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory

What is the result of:

packageVersion("rstan")
packageVersion("StanHeaders")

Yes I do. Here is the actual output. It is possible I missed something, but I think it is the same error as above.

`Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! g++.exe: error: Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
g++.exe: error: Files/R/R-3.6.2/library/StanHeaders/include: No such file or directory
g++.exe: error: Files/R/R-3.6.2/library/RcppEigen/include: No such file or directory
make: *** [C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf:215: fileff83e8625cb.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB fileff83e8625cb.cpp 2> fileff83e8625cb.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

packageVersion(“rstan”)
[1] ‘2.19.3’
packageVersion(“StanHeaders”)
[1] ‘2.21.0.1’

You need both StanHeaders and rstan to be 2.19.x. In a clean R session, just do a

remove.packages(c("StanHeaders", "rstan"))
file.remove(".RData")
# restart R
install.packages(c("StanHeaders", "rstan"))

That doesn’t seem to solve it. I am still getting version 2.21.X Is there a way to specify which version I need?

remove.packages(c(“StanHeaders”, “rstan”))
Removing packages from ‘C:/Program Files/R/R-3.6.2/library’
(as ‘lib’ is unspecified)

I have tried both:

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

and

install.packages(c(“StanHeaders”, “rstan”))
trying URL ‘https://cran.rstudio.com/bin/windows/contrib/3.6/StanHeaders_2.21.0-1.zip
Content type ‘application/zip’ length 2359184 bytes (2.2 MB)
downloaded 2.2 MB

trying URL ‘https://cran.rstudio.com/bin/windows/contrib/3.6/rstan_2.19.3.zip
Content type ‘application/zip’ length 4734399 bytes (4.5 MB)
downloaded 4.5 MB

package ‘StanHeaders’ successfully unpacked and MD5 sums checked
package ‘rstan’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\User\AppData\Local\Temp\Rtmp44eSx2\downloaded_packages

library(rstan)
Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.19.3, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
For improved execution time, we recommend calling
Sys.setenv(LOCAL_CPPFLAGS = ‘-march=corei7 -mtune=corei7’)
although this causes Stan to throw an error on a few processors.

packageVersion(“rstan”)
[1] ‘2.19.3’
packageVersion(“StanHeaders”)
[1] ‘2.21.0.1’

Since its not automatically picking up the right version, you’ll need to manually specify the version to install:

require(devtools)
install_version("StanHeaders", version = "2.19.0", repos = "http://cran.us.r-project.org")

Good luck!

3 Likes

Thank you, this solved it. For some reason the first time I ran the code, it could not find the package, but running it again worked.

I am having the same problem but the solution above is not working. I get the following:

  • installing source package ‘StanHeaders’ …
    ** package ‘StanHeaders’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** libs

*** arch - i386
then a huge number of warnings, mainly ‘variable set but not used’ , ‘array subscript is below array bounds [-Warray-bounds]’
then it finishes with:
C:/RBuildTools/3.5/mingw_32/bin/gcc -I"C:/Users/J5116~1.BRO/DOCUME~1/R/R-36~1.3/include" -DNDEBUG -DNO_FPRINTF_OUTPUT -I"…/inst/include" -include stan_sundials_printf_override.hpp -O3 -Wall -std=gnu99 -mtune=core2 -c init.c -o init.o
C:/RBuildTools/3.5/mingw_32/bin/gcc -shared -s -static-libgcc -o StanHeaders.dll tmp.def cvodes/cvodes.o cvodes/cvodes_io.o cvodes/cvodea.o cvodes/cvodea_io.o cvodes/cvodes_direct.o cvodes/cvodes_diag.o cvodes/cvodes_spils.o cvodes/cvodes_bandpre.o cvodes/cvodes_bbdpre.o sundials/sundials_sparse.o sundials/sundials_dense.o sundials/sundials_nvector.o sundials/sundials_pcg.o sundials/sundials_math.o sundials/sundials_sptfqmr.o sundials/sundials_linearsolver.o sundials/sundials_iterative.o sundials/sundials_spgmr.o sundials/sundials_spbcgs.o sundials/sundials_spfgmr.o sundials/sundials_band.o sundials/sundials_version.o sundials/sundials_direct.o sundials/sundials_matrix.o sunmat_band/sunmatrix_band.o sunmat_band/fsunmatrix_band.o sunmat_dense/fsunmatrix_dense.o sunmat_dense/sunmatrix_dense.o sunlinsol_band/sunlinsol_band.o sunlinsol_dense/sunlinsol_dense.o idas/idaa.o idas/idaa_io.o idas/idas.o idas/idas_bbdpre.o idas/idas_direct.o idas/idas_ic.o idas/idas_io.o idas/idas_spils.o nvec_ser/nvector_serial.o init.o -LC:/Users/J5116~1.BRO/DOCUME~1/R/R-36~1.3/bin/i386 -lR
make: *** [C:/Users/J5116~1.BRO/DOCUME~1/R/R-36~1.3/share/make/winshlib.mk:13: StanHeaders.dll] Error 127
ERROR: compilation failed for package ‘StanHeaders’

  • removing ‘C:/Users/j.browne/Documents/R/R-3.6.3/library/StanHeaders’
  • restoring previous ‘C:/Users/j.browne/Documents/R/R-3.6.3/library/StanHeaders’

I would be very grateful for any help you could give me

Can you try the steps in this post and see if it works:

I also am getting this error with the example() model on Windows 7, R 4.0.2, and versions:

packageVersion(“rstan”)
[1] ‘2.21.2’
packageVersion(“StanHeaders”)
[1] ‘2.21.0.6’

any other guidance?

Compilation argument:
C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB filedec7e4f5a8e.cpp 2> filedec7e4f5a8e.cpp.err.txt
“C:/rtools40/mingw64/bin/“g++ -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.2/include” -DNDEBUG -I"C:/Program Files/R/R-4.0.2/library/Rcpp/include/” -I"C:/Program Files/R/R-4.0.2/library/RcppEigen/include/" -I"C:/Program Files/R/R-4.0.2/library/RcppEigen/include/unsupported" -I"C:/Program Files/R/R-4.0.2/library/BH/include" -I"C:/Program Files/R/R-4.0.2/library/StanHeaders/include/src/" -I"C:/Program Files/R/R-4.0.2/library/StanHeaders/include/" -I"C:/Program Files/R/R-4.0.2/library/RcppParallel/include/" -I"C:/Program Files/R/R-4.0.2/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include “C:/Program Files/R/R-4.0.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp” -std=c++1y -include C:/Program Files/R/R-4.0.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp -I “C:/Program Files/R/R-4.0.2/library/StanHeaders/include” -I “C:/Program Files/R/R-4.0.2/library/RcppEigen/include” -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c filedec7e4f5a8e.cpp -o filedec7e4f5a8e.o
g++.exe: error: Files/R/R-4.0.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
make: *** [C:/PROGRA~1/R/R-40~1.2/etc/x64/Makeconf:229: filedec7e4f5a8e.o] Error 1
Error in file(con, “r”) : cannot open the connection
In addition: Warning messages:
1: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found
2: In file(con, “r”) :
cannot open file ‘filedec7e4f5a8e.cpp.err.txt’: No such file or directory

Can you restart R and then run:

devtools::session_info("rstan")

And post the output?

Below is the output requested.

However, I got it to run after I did some troubleshooting with the rlang package. It wanted to update to v0.4.8 from source, but when I did that it errored out. when I reverted to the binary version, it was successful.

Not sure why that mattered, but I got the idea when trying to install brms and it was erroring out on the rlang package.

Thanks,

devtools::session_info(“rstan”)

  • Session info ---------------------------------------------------------------------------------------
    setting value
    version R version 4.0.2 (2020-06-22)
    os Windows 7 x64 SP 1
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate English_United States.1252
    ctype English_United States.1252
    tz America/Chicago
    date 2020-10-13

  • Packages -------------------------------------------------------------------------------------------
    package * version date lib source
    assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0)
    backports 1.1.10 2020-09-15 [1] CRAN (R 4.0.2)
    BH 1.72.0-3 2020-01-08 [1] CRAN (R 4.0.0)
    callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.0)
    checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.0)
    cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0)
    colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.0)
    crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0)
    curl 4.3 2019-12-02 [1] CRAN (R 4.0.0)
    desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.0)
    digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0)
    ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.0)
    evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0)
    fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0)
    farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.0)
    ggplot2 3.3.2 2020-06-19 [1] CRAN (R 4.0.2)
    glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
    gridExtra 2.3 2017-09-09 [1] CRAN (R 4.0.0)
    gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0)
    inline 0.3.16 2020-09-06 [1] CRAN (R 4.0.2)
    isoband 0.2.2 2020-06-20 [1] CRAN (R 4.0.2)
    jsonlite 1.7.1 2020-09-07 [1] CRAN (R 4.0.2)
    labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0)
    lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.2)
    lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0)
    loo 2.3.1 2020-07-14 [1] CRAN (R 4.0.2)
    magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0)
    MASS 7.3-51.6 2020-04-26 [1] CRAN (R 4.0.0)
    Matrix 1.2-18 2019-11-27 [1] CRAN (R 4.0.2)
    matrixStats 0.57.0 2020-09-25 [1] CRAN (R 4.0.2)
    mgcv 1.8-31 2019-11-09 [1] CRAN (R 4.0.2)
    munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0)
    nlme 3.1-148 2020-05-24 [1] CRAN (R 4.0.0)
    pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.2)
    pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 4.0.2)
    pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0)
    pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.0)
    praise 1.0.0 2015-08-11 [1] CRAN (R 4.0.0)
    prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0)
    processx 3.4.4 2020-09-03 [1] CRAN (R 4.0.2)
    ps 1.4.0 2020-10-07 [1] CRAN (R 4.0.2)
    R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.0)
    RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.0)
    Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.2)
    RcppEigen 0.3.3.7.0 2019-11-16 [1] CRAN (R 4.0.0)
    RcppParallel 5.0.2 2020-06-24 [1] CRAN (R 4.0.2)
    rlang 0.4.7 2020-07-09 [1] CRAN (R 4.0.2)
    rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.0)
    rstan 2.21.2 2020-07-27 [1] CRAN (R 4.0.2)
    rstudioapi 0.11 2020-02-07 [1] CRAN (R 4.0.0)
    scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.0)
    StanHeaders 2.21.0-6 2020-08-16 [1] CRAN (R 4.0.2)
    testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.0)
    tibble 3.0.1 2020-04-20 [1] CRAN (R 4.0.0)
    utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.0)
    V8 3.2.0 2020-06-19 [1] CRAN (R 4.0.2)
    vctrs 0.3.4 2020-08-29 [1] CRAN (R 4.0.2)
    viridisLite 0.3.0 2018-02-01 [1] CRAN (R 4.0.0)
    withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.2)

[1] C:/Program Files/R/R-4.0.2/library

1 Like

Glad to hear it’s working! I’ll look into the latest version of rlang and see if there’s going to be an issue we need to take care of