For posterity, I thought I’d mention within this thread that I had every issue exactly as listed and tested by Chris above. Unfortunately, after following all of the suggestions, I still couldn’t get the example model to compile.
However, after going through these instructions and then also adding to my makevars file the line:
CXX14 = C:/Rtools40/mingw64/bin/g++
…everything worked out.
My makevars.win file now reads:
CXX14FLAGS += -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2
CXX14 = C:/Rtools40/mingw64/bin/g++
I took this advice from an older comment by @bgoodri here: G++ Compile Error With R Package