Error in rstan compilation after installation of Rtools

First time user of rstan/Rtools here. After installing Rtools 43 and rstan and
running the test model
example(stan_model, package = “rstan”, run.dontrun = TRUE)

I see the following error message…

“Error in compileCode(f, code, language = language, verbose = verbose) :
/bin/sh: line 1: g++: command not foundmake: *** [C:/PROGRA~1/R/R-44~1.0/etc/x64/Makeconf:296: file2490587a21dd.o] Error 127”

After searching throuch discourse and online, none of the fixes solved this error

Here is some relevant results based on requests seen in other threads:

Sys.which(“make”)
make
“C:\rtools43\usr\bin\make.exe”
Sys.getenv(“BINPREF”)
[1] “”
readLines(“~/.Renviron”)
[1] “PATH="{RTOOLS43_HOME}\\usr\\bin;{PATH}"”
readLines(“~/.R/Makevars.win”)
[1] “”
[2] " CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2"
Sys.getenv(“R_LIBS_USER”)
[1] “C:\Users\chris\AppData\Local/R/win-library/4.4”

And lastly…

Sys.getenv(“PATH”)
[1] “c:\rtools44\x86_64-w64-mingw32.static.posix\bin;c:\rtools44\usr\bin;C:\rtools43\usr\bin;C:\rtools43\usr\bin;C:\Program Files\R\R-4.4.0\bin\x64;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\chris\AppData\Local\Microsoft\WindowsApps;C:\Program Files\RStudio\resources\app\bin\quarto\bin;C:\Program Files\RStudio\resources\app\bin\postback”


Operating System: Windows11 Pro
R Version: 4.4.0
Rtools 4.3
rstan: 2.32.6
RStudio:  2024.04.2

Thank you. -Chris

After additional searches, I attempting the following suggestion:

Compile packages using all cores

Sys.setenv(MAKEFLAGS = paste0(“-j”,parallel::detectCores()))

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

I see a similar error in embedded in the results:
/bin/sh: line 1: g++: command not found
make: *** [C:/PROGRA~1/R/R-44~1.0/etc/x64/Makeconf:296: Module.o] Error 127
ERROR: compilation failed for package ‘rstan’

-Chris

After continued investigation and searches… Looks like rookie mistake on my part for not running the Rtools4.4 with R 4.4

After uninstalling Rtools4.3, installing Rtools 4.4 (updating .Renviron), removing the rstan and StanHeaders packages, reinstalling rstan and StanHeaders from source, and restarting the laptop I was able to successfully run the RStan example/test model.

-Chris

Thanks for reporting the solution. You might find cmdstanr easier to install and use in the future—it doesn’t have the same deep binary dependencies as RStan and isn’t held back by CRAN.