C++14 standard requested but CXX14 is not defined

If you followed
then it should be okay for the time being.

This is quick reply to thank you. I will try.

By execute the following code, I did install the rstan package.

Thank you!!

I’m trying to troubleshoot this same error but the link you’ve posted is taking me to a blank page at the moment.

Thank you!

Just in case the link breaks in the future, here’s the relevant section of code to be run from R after having installed Rtools but before installing rstan:

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "Makevars.win")
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native",
    "CXX14 = g++ -m$(WIN) -std=c++1y",
    "CXX11FLAGS=-O3 -march=native",
    file = M, sep = "\n", append = TRUE)

In my particular case, I also had to edit this line

"CXX14 = g++ -m$(WIN) -std=c++1y"

and replace g++ with the full path C:/Rtools/mingw_64/g++.exe


I uninstalled rstan, ran the code as instructed, reinstalled rstan, and the error has now changed to the following:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file17e86c9243ea.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file17e86c9243ea.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file17e86c9243ea.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file17e86c9243ea.o] Error 1

Error in sink(type = “output”) : invalid connection

I would just

1 Like

Many thanks, sir. That fixed it.

Hi there!
Thanks for your suggestion. However, I still cannot make it work. Changing the code does nothing for me.
I still got this message: Error in sink(type = “output”) : invalid connection.
The Rstan 2.19.1.zip link is no longer awailable and it reports an error when you install it from the Tools bar.
This is my current Makevars.win file:
CXX14 = g++ -m$(WIN) -std=c++1y
CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=native -mtune=native

Rstudio 1.2.13
Rstan 2.18

I’ve even tried installing a different Rstudio version… No luck with that either.

Thanks in advance!

Try this link now

install.packages("https://win-builder.r-project.org/rTkumr03G8UM/rstan_2.19.1.zip", repos = NULL)
1 Like

Thank you very much for your help!!! You saved me!!

Hello. I am having difficulty completing the steps laid out in RStan Getting Started · stan-dev/rstan Wiki · GitHub (retried everything several times). I am able to verify the toolchain by successfully installing jsonlite from the source, but get the error message seen in the example when I try to install rstan. When I attempt to install rstan from the source, here is the final portion of the output…

testing if installed package keeps a record of temporary installation path

  • DONE (StanHeaders)
  • installing source package ‘rstan’ …
    ** package ‘rstan’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** libs

*** arch - i386
Error in .shlib_internal(args) :
C++14 standard requested but CXX14 is not defined

  • removing ‘C:/Users/Ann/Documents/R/win-library/3.6/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

I have followed the code for configuring c++ for R 3.6 from the github page (I have version 3.6.1) and I have Rstudio 1.41106. I have downloaded Rtools 3.5. My Makevars file reads:
STANHEADERS_SRC = (shell "(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e “message()” -e “cat(system.file(‘include’, ‘src’, package = ‘StanHeaders’, mustWork = TRUE))” -e “message()” | grep “StanHeaders”)

PKG_CPPFLAGS = -I"…/inst/include" -I"(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DRCPP_PARALLEL_USE_TBB=1 PKG_CXXFLAGS = (shell “(R_HOME)/bin(R_ARCH_BIN)/Rscript” -e “RcppParallel::CxxFlags()”) (shell "(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e “StanHeaders:::CxxFlags()”)
PKG_LIBS = (shell "(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e “RcppParallel::RcppParallelLibs()”) (shell "(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e “StanHeaders:::LdFlags()”)

Please how can I define CXX14? Thanks in advance.

I just need a little more info about your system, can you post the outputs from:


[1] “C:/Rtools35/mingw_$(WIN)/bin/”

[1] “”
[2] " CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2"
[1] “Sys.setenv(BINPREF = “C:/Rtools35/mingw_$(WIN)/bin/”)”


Great, we just need to edit your Makevars.win to tell R where to find the compiler. Can you run:

cat("\n CXX14 = $(BINPREF)g++",
    file = "~/.R/Makevars.win", sep = "\n", append = TRUE)

Then restart R and try the install from source again?

No dice. I uninstalled all packages (Rtools, pkgbuild, coda, mvtnorm, devtools–the last three I know are after the fact), shut down my computer reinstalled Rtools 35, reconfigured R for C++, was able to install jsonlite from the source, followed the steps for Rstan getting started, tried to install Rstan from the source, had the same error as before about the Makevars not being defined. The edits to Makevars are being registered in R but the actual Makevars file remains unchanged (unsure if it should change):
[1] “C:/Rtools/mingw_$(WIN)/bin/”

[1] “”
[2] " CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2"
[3] “”
[4] " CXX14 = (BINPREF)g++" [5] "" [6] " CXX14 = (BINPREF)g++"
[7] “”
[8] " CXX14 = (BINPREF)g++" readLines("~/.Rprofile") [1] "Sys.setenv(BINPREF = \"C:/Rtools/mingw_(WIN)/bin/")"

Happy to entertain other ideas. Thanks.

Looks like CXX14 might need an additional flag. Can you try running:

cat(c("\n CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2",
      "CXX14 = $(BINPREF)g++ -std=c++1y"),
    file = "~/.R/Makevars.win", sep = "\n", append = FALSE)

Then restarting R and trying the RStan install again?

Hi. I was able to get stan to load and the example to run. For your notes, I got a warning message: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) : ‘C:/Rtools/mingw_/bin/g++’ not found.

Really appreciate the help and quick support.

Is there a updated link for now? I have the same issue but the link does not work anymore.