Problem installing rstan

Short summary of the problem
I get errors when I tested the stan_model example. I followed instructions provided and everything looked good, but I get the following error:
Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) :
C:/rtools40/mingw32/bin/…/lib/gcc/i686-w64-mingw32/8.3.0/…/…/…/…/i686-w64-mingw32/bin/ld.exe: C:/Users/Owner/Documents/R/win-library/4.0/rstan/lib/i386/libStanServices.a(stan_fit.o):stan_fit.cpp:(.rdata$_ZZN5boost4math6detail9bessel_y0IeNS0_8policies6policyINS3_13promote_floatILb0EEENS3_14promote_doubleILb0EEENS3_14default_policyES9_S9_S9_S9_S9_S9_S9_S9_S9_S9_EEEET_SB_RKT0_E2P1[_ZZN5boost4math6detail9bessel_y0IeNS0_8policies6policyINS3_13promote_floatILb0EEENS3_14promote_doubleILb0EEENS3_14default_policyES9_S9_S9_S9_S9_S9_S9_S9_S9_S9_EEEET_SB_RKT0_E2P1]+0x0): multiple definition of `boost::math::detail::bessel_y0<long double, boost::math::policies::policy<boost::math::policies::promote_float, boost::math::policies::promote_double, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_pol
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
'C:/rtools40/usr/mingw
/bin/g++’ not found.

I am new to the forum and not quite sure if this is the correct way to ask for help or submit a question!!

Thanks

Hi Alex,

To fix this you just need to reinstall RStan and StanHeaders from source:

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

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

Hi Andrew!

Thank you so much for responding! I have been trying to install rstan for several days now and it has been a bit challenging!

OK. Will remove StanHeaders and rstan and reinstall using the code you provided.

Thanks
Alex-