Problems configuring Makevars.win since R 3.6.0

I had been happily using Rstan on several Windows 10 machines with R 3.5.3. However, after updating each to R 3.6.0, I have been unable to compile the C++ code for Stan. The error messages suggest that there are problems finding the C++14 standard.

To troubleshoot, I uninstalled R and Rtools and then reinstalled R 3.6.0 and Rtools 3.5 in the default locations. I then followed the instructions on https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started and got the following error when I ran the stan() command:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! Error in .shlib_internal(commandArgs(TRUE)) : 
  C++14 standard requested but CXX14 is not defined
Calls: <Anonymous> -> .shlib_internal
Execution halted
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command 'C:/PROGRA~1/R/R-3.6.0/bin/x64/R CMD SHLIB file31c4b6d5db0.cpp 2> file31c4b6d5db0.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

My Makevars.win file includes the following:

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=native -mtune=native

I assume that it is looking for a definition for CXX14 but that is not there by default. So even though Rtools is installed, R does not seem to finding g++ correctly.

This is all a bit over my head, so any advice would be really appreciated.

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.

Thanks for the quick response. Following the instructions on the page you linked, I updated the Makevars to:

CXX14=$(BINPREF)g++ -O2 -march=native -mtune=native
CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=native -mtune=native

This allowed me to run a model that I know worked previously. It completed in around 580 seconds.
Then I tried again after removing -O2 and it completed again in around 580 seconds.

1 Like

Curious.

In a (perhaps) related issue, I am now getting the following error when I try to use cores > 1:

Error in unserialize(socklist[[n]]) : error reading from connection
Error in serialize(data, node$con, xdr = FALSE) : error writing to connection

Any ideas on how to troubleshoot this?

If it’s in RStudio then I assume you are hitting a bug related to mc.cores and its ilk. Does it work in console R? If so then it’s a known RStudio issue.

Here is some discussion: https://stat.ethz.ch/pipermail/r-devel/2019-April/077632.html. I don’t actually know what error it would cause as I’ve never encountered it before.

@bgoodri, @jonah is the $(BINPREF) the canonical answer for R 3.6 on Windows moving forwards? Can the RStan quick start for Windows be updated if so? This caused a bunch of issues in my course last week that were eventually solved by prefixing BINPREF by hand.

It might be canonical for today. It shouldn’t be necessary going forward now that we use pkgbuild, but I haven’t yet been able to get a rstan 2.19 onto CRAN without breaking a bunch of other packages.

Note that it was also helpful for me to move from RTools 3.5 to 4.0 following the instructions on this page: