Workarounds for current Rstan Windows issues

This is a list of the current RStan Windows problems and known temporary workarounds:

  1. Error includes something about prim/mat/fun/Eigen.hpp

If your error is similar to

g++.exe: error: Files/R/R-4.0.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:
No such file or directory

or anything that mentions stan/math/prim/mat/fun/Eigen.hpp

UPDATE (24.8.2020):

This issue was fixed in the latest version of StanHeaders (2.21.0-6), so make sure you have the latest version of the StanHeaders package.

  1. Error include /bin/x64/R CMD SHLIB something.cpp 2>

If your error is similar to

In system(cmd, intern = !verbose) :
running command 
‘C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file2968734e19d4.cpp 2>
 file2968734e19d4.cpp.err.txt’ had status 1

This is an issue with the inline package. Current workaround is to install it with

  1. Error include something about `mingw32/bin/ld.exe:

If you see an error containing something like mingw32/bin/ld.exe: cannot find Files: No such file or directory, for example

C:/Program Files (x86)/rtools40/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find C:/Program: No such file or directory
C:/Program Files (x86)/rtools40/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find Files: No such file or directory

This is because you have installed RTools in a location that contains spaces (most likely C:/Program Files/RTools/...)

I believe this is an issue with R in general, as I am unable to install any package (non-rstan related) from source with RTools installed in a location with spaces.

  1. You experience frequent R session crashes

This is very likely an issue with compile flags. In this case, open the file.
If you do not know where your is located, run

file.path(Sys.getenv("HOME"), ".R", "")

open the file and remove any mention of march=native from the file.

Also double check the Renviron file that can be found at

file.path(Sys.getenv("HOME"), ".R", ".Renviron")
  1. Warning about mingw_/bin/g++ not found

If a warning similar to below is printed:

In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found

You can safely ignore this. This will go away in the next bugfix release. Your models work fine even if you see these warnings.

Other advice in case of other problems not listed above:

  • if you are using R4.x, run Sys.getenv("PATH"). It should start with "C:\rtools40\usr\bin;". If it does not, run
writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")

and restart R/Rstudio.

@everyone Feel free to edit the post if there are other known workarounds for known issues or any of the workarounds have better options.


The quick advice to avoid many of the RStan Windows issues:

  • do not install RTools in a path with spaces. If possible, install in the default location (C:/Rtools40)
  • place your R package library in a path without spaces
  • if you are using R 4.0, make sure to install RTools 4.0 and run
writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")

after installation (and then restart R). This is suggested in RTools instructions as well.

@bgoodri compilation not working if RTools is installed in a path with spaces and brackets is an R issue. Does it make sense to report that, given that its a general R issue? And where does one report that if yes?


Thanks for this writeup! I’ve pinned the topic so hopefully it’s seen when people come to post issues


This error should not exist with StanHeaders 2.21.0-6, so install that.

Cool, thanks. Updated the “workaround” with this final solution.