Error in model fit: C++14 standard requested but CXX14 is not defined
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
Summary:
Error message relating to C++compiler when running a linear model fit.
Description:
I am new to Stan and RStan and trying out the tutorial by Max Farrell and Isla Myers-Smith on:
https://ourcodingclub.github.io/2018/04/17/stan-intro.html
The step by step process is shown below under 'Reproducible Steps'.
When I run the stanc() it compiles fine. But when I fit the linear model I receive the following error message:
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: -> .shlib_internal
Execution halted
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command 'C:/PROGRA1/R/R-351.1/bin/x64/R CMD SHLIB file55c71d73e8e.cpp 2> file55c71d73e8e.cpp.err.txt' had status 1
I've searched everywhere for possible solutions. I reviewed the following issue posted by yanys7
https://github.com/stan-dev/rstan/issues/565
As suggested by bgoodri I created a ~/.R/Makevars file and inserted the following:
CXX14 = g++
However the problem still persists.
I don't know if this is a bug or if I'm doing something wrong.
Thanks in advance for any help you can provide.
Reproducible Steps:
This follows almost exactly the steps shown in the tutorial.
Sys.setenv(USE_CXX14 = 1)
library(rstan)
library(gdata)
library(bayesplot)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
seaice <- read.csv("seaice.csv", stringsAsFactors = F)
colnames(seaice)<-c("year", "extent_north", "extent_south")
x <- I(seaice$year - 1978)
y <- seaice$extent_north
N <- length(seaice$year)
stan_data <- list(N = N, x = x, y = y)
write("// Stan model for simple linear regression
data {
int <lower = 1> N;
vector[N] x;
vector[N] y;
}
parameters {
real alpha;
real beta;
real<lower = 0> sigma;
}
model {
y ~ normal(alpha + x * beta, sigma);
}
generated quantities {
},
"stan_model1.stan")
stanc("stan_model1.stan")
stan_model1 <- "stan_model1.stan"
fit <- stan(file = stan_model1, data = stan_data, warmup = 500, iter = 1000, chains = 4, thin = 1)
Current Output:
The output from stanc("stan_model1.stan") is below:
$status
[1] TRUE
$model_cppname
[1] "model55c23451a60_stan_model1"
$cppcode
[1] "// Code generated by Stan version 2.17.0\n\n#include <stan/model/model_header.hpp>\n\nnamespace model55c23451a60_stan_model1_namespace {\n\nusing std::istream;\nusing std::string;\nusing std::stringstream;\nusing std::vector;\nusing stan::io::dump;\nusing stan::math::lgamma;\nusing stan::model::prob_grad;\nusing namespace stan::math;\n\ntypedef Eigen::Matrix<double,Eigen::Dynamic,1> vector_d;\ntypedef Eigen::Matrix<double,1,Eigen::Dynamic> row_vector_d;\ntypedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> matrix_d;\n\nstatic int current_statement_begin__;\n\nstan::io::program_reader prog_reader__() {\n stan::io::program_reader reader;\n reader.add_event(0, 0, "start", "model55c23451a60_stan_model1");\n reader.add_event(19, 19, "end", "model55c23451a60_stan_model1");\n return reader;\n}\n\nclass model55c23451a60_stan_model1 : public prob_grad {\nprivate:\n int N;\n vector_d x;\n vector_d y;\npublic:\n model55c23451a60_stan_model1(stan::io::va...
$model_name
[1] "stan_model1"
$model_code
[1] "// Stan model for simple linear regression\ndata {\n int <lower = 1> N; // Sample size\n vector[N] x; //Predictor\n vector[N] y; // Outcome\n}\n\nparameters {\n real alpha; //Intercept\n real beta; // Slope\n real<lower = 0> sigma; //Error SD\n}\n\nmodel {\n y ~ normal(alpha + x * beta, sigma);\n}\n\ngenerated quantities {\n} // The posterior predictive distribution"
attr(,"model_name2")
[1] "stan_model1"
Expected Output:
If applicable, the output you expected from RStan.
RStan Version:
RStan version 2.17.3
R Version:
R Version 3.5.1
Operating System:
Windows 8 64bit
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied R script with RStan 2.17.3 on Windows 8, then inspect the ~/.R/Makevars CXX14 setting and the compiler invocation shown in the error. The issue is resolved when the linear-model fit compiles and runs without the “CXX14 is not defined” error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, r
- Domain
- build-system, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100