I believe this has been solved here: Running rstan with latest R (3.6.0) fails with Error in compileCode
Though of course you may want to try to see if it works without -O2
since that will reduce runtime performance. And may not be a necessary part of the solution. I can’t confirm.