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:
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: