C++14 standard requested but CXX14 is not defined

When I was running the following code, R told me ’ C++14 standard requested but CXX14 is not defined’.

Sys.setenv(USE_Cxx14 = 1)
require(“rstan”) # observe startup messages

mstring = "data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // s.e. of effect estimates
}
parameters {
real mu;
real<lower=0> tau;
real eta[J];
}
transformed parameters {
real theta[J];
for (j in 1:J)
theta[j] = mu + tau * eta[j];
}
model {
target += normal_lpdf(eta | 0, 1);
target += normal_lpdf(y | theta, sigma);
}
"
smodel <- stan_model(model_code = mstring)

You need to put

CXX14 = g++ # or clang++ if you have that
CXX14FLAGS = -O3

into your ~/.R/Makevars file.

3 Likes

Just Now, I encountered this issue when I try to install rstan package. I cannot understand your suggestion sorry I am beginner.
Please let me ask what the following means;

" into your ~/.R/Makevars file".

In the following directory, there is not a file named Makevars.file:
C:\Program Files\R

If you followed
https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Windows#configuration
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

2 Likes

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.