Error in compileCode(f, code, language = language, verbose = verbose) : make: *** [C:/PROGRA~1/R/R-41~1.1/etc/x64/Makeconf:245: file9ba85b357e80.o] Error 1

I installed rstan from the “source”. I made sure rtools40 is up to date and created the .Renviron file in Documents. Made sure there is no .Rprofile file. But I am still getting an error when running the example model.

> library(rstan)
Loading required package: StanHeaders
Loading required package: ggplot2
Need help getting started? Try the R Graphics Cookbook: https://r-graphics.org
rstan (Version 2.21.2, 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)
Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file
> example(stan_model, package = "rstan", run.dontrun = TRUE)
Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
           clone_impl:                   ^C:/Users/chascott/Documents/R/win-library/4.1/BH/include/boost/exception/exception.hpp:472:9: error: expected declaration before '}' token         }         ^make: *** [C:/PROGRA~1/R/R-41~1.1/etc/x64/Makeconf:245: file3c4470556947.o] Error 1
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/rtools40/usr/mingw_/bin/g++' not found

Sorry for the delay in getting to this one. Can you post the output from the following commands, I just need some information about your setup:

Sys.getenv("PATH")
Sys.getenv("BINPREF")
readLines("~/.R/Makevars.win")
readLines("~/.Renviron")
readLines("~/.Rprofile")

Sys.getenv(“PATH”)
[1] “C:\rtools40\usr\bin;C:\Program Files\R\R-4.1.1\bin\x64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath_target_4305328;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\cs\AppData\Local\Microsoft\WindowsApps;C:\Program Files\PuTTY;C:\Program Files\Amazon\AWSCLIV2;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\Azure Data Studio\bin;C:\Program Files\nodejs;C:\Users\cs\Anaconda3;C:\Users\cs\Anaconda3\Scripts;;\Scripts;C:\Users\cs\AppData\Local\Microsoft\WindowsApps;C:\Users\cs\AppData\Local\GitHubDesktop\bin;C:\Users\cs\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Azure Data Studio\bin;C:\Users\cs\Anaconda3;C:\Users\cs\Anaconda3\Scripts”

Sys.getenv(“BINPREF”)
[1] “”

readLines(“~/.R/Makevars.win”)
[1] “CXX14FLAGS += -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2”

readLines(“~/.Renviron”)
[1] “PATH="{RTOOLS40_HOME}\\usr\\bin;{PATH}"”

readLines(“~/.Rprofile”)
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘C:/Users/cs/Documents/.Rprofile’: No such file or directory

Can you try reinstalling rstan’s dependencies:

install.packages(c("BH","RcppEigen","RcppParallel"))

And then reinstalling rstan from source:

# Compile packages using all cores
Sys.setenv(MAKEFLAGS = paste0("-j",parallel::detectCores()))

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