Search code examples
stanrstan

Error on the stan file compilation using R 3.6.0. and Win 10


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-36~1.0/bin/x64/R CMD SHLIB file1a1860a0379.cpp 2> file1a1860a0379.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

Some non-English page said that we can overcome by executing the following R script, but it did not work in my case:

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) 
  dir.create(dotR)
M <- file.path(dotR, "Makevars")
if (!file.exists(M)) 
  file.create(M)
cat("\nCXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function",
    "CXX14 = g++ -std=c++1y",
    file = M, sep = "\n", append = TRUE)

The above R script is same as in the following page:

https://github.com/stan-dev/rstan/issues/569


I tried to uninstall and install according to the following page, but the above error occurred.

Rstan installation: https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started

REF; https://github.com/stan-dev/stan/issues/1613

ref: https://github.com/stan-dev/rstan/issues/633


Solution

  • For me, the issue has been solved by adding manually the following line into the file .R/Makevars.win.

    CXX14 = "C:\Rtools\mingw_64\bin\g++.exe"