RStan Compilation ERROR

Hello, I see there is a long recent thread about similar issues, but I’ve tried the solutions in that one and none have seemed to work. I have tried to follow steps as best I can, and get no error message when I install rstan using:

install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)

But then when I try

example(stan_model, package = "rstan", run.dontrun = TRUE)

I get this error message:

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) :
sh: g++: command not foundmake: *** [C:/PROGRA~1/R/R-40~1.3/etc/x64/Makeconf:229: file2360baa1170.o] Error 127

EDIT: Sorry I should have added I’m on a Windows, running R 4.0.

I think you are getting multiple errors here?
I am new to RStan and trying hours now… lol…
I was able to get rid of the following error,

sh: g++: command not foundmake:

by changing Makevars.win

from

CXXX14 = g++

to

CXX14 = “C:\rtools40\mingw64\bin\g++”

Still trying to figure out this error (mine has multiple lines below…)

Error in compileCode(f, code, language = language, verbose = verbose) :

Here is my platform info

platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
version.string R version 4.0.1 (2020-06-06)

I think now my rstan is finally working.
Here is what I did.

  1. Fixed sh: g++ error first.
    I did this by changing Makevars.win
    from

CXX14 = g++

to

CXX14 = “C:\rtools40\mingw64\bin\g++”

Just changed that one line. Not exactly sure what this is, but it appears that, originally CXX14 was referring to g++ without specifying any directory, but the fix specifies the directory. (I think I saw this from one of the troubleshooting tips from an earlier version of the rtool section.

  1. Then, reinstalled rstan from the source by following this page

Installing RStan from Source · stan-dev/rstan Wiki · GitHub

Then, it worked.
Before I fix the sh:g++ error, I could not even install from the source. I have seen many people reporting that their errors are solved when installing from the source.
Hope it helps.

Thanks for the help. I actually fixed it yesterday, although I don’t even really know how–I was following along with other threads and I think what I did was delete the Makevars.win file on my computer, restarted R, and then that seemed to fix it? I think that had basically the same effect as what you did.

1 Like