# R-stan compilation Error possibly related to c++14

**URL:** <https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947>\
**Category:** Interfaces\
**Tags:** rstan\
**Created:** [October 9, 2018, 4:20pm UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947 "2018-10-09T16:20:18Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Potanin](https://avatars.discourse-cdn.com/v4/letter/p/a698b9/32.png) [@Potanin](https://discourse.mc-stan.org/u/Potanin)\
**Post date:** [October 9, 2018, 4:20pm UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/1 "2018-10-09T16:20:18Z")

</div>

Hello, stan community!

Additional discussion on problem I am dealing with could be found [there](https://stackoverflow.com/questions/52721672/r-stan-8schools-example-faile/52724262?noredirect=1#comment92374693_52724262)

I am trying to run classical r-stan example from this official [tutorial](https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started#how-to-use-rstan). But I can’t because I get the following error message:

 ![](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/9/9df0065d73296264fd01ed754cf79d888797a53c.png)

[Ben Goodrich](https://stackoverflow.com/users/1762912/ben-goodrich) suggested to set Sys.setenv(USE\_CXX14=1) and include the following lines to Makevars file:

CXX14=g++  
CXX14FLAGS=-O3

But I still get the same error message. I also have been trying to install.packages(“[https://win-builder.r-project.org/OdTz9MCBT96j/rstan\_2.18.1.zip](https://win-builder.r-project.org/OdTz9MCBT96j/rstan_2.18.1.zip)”, repos = NULL) but then I can’t run library(‘rsatn’) as I get:

Error: package or namespace load failed for ‘rstan’ in rbind(info, getNamespaceInfo(env, “S3methods”)):  
number of columns of matrices must match (see arg 2)

Please help me to figure out this problem.

Will be very greatfull for help!

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [October 9, 2018, 6:00pm UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/2 "2018-10-09T18:00:58Z")

</div>

When you get the error involving `rbind(info, getNamespaceInfo(env, "S3methods"))`, can you post the output of `traceback()`. Also, when restarting R you have to make sure that there are no `stanfit` objects being autoloaded into your session via the `.RData` file in the startup directory.

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [October 9, 2018, 6:55pm UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/3 "2018-10-09T18:55:04Z")

</div>

Is it working now?

---

<div class="post-metadata">

**Author:** ![Potanin](https://avatars.discourse-cdn.com/v4/letter/p/a698b9/32.png) [@Potanin](https://discourse.mc-stan.org/u/Potanin)\
**Post date:** [October 11, 2018, 2:39am UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/4 "2018-10-11T02:39:40Z")

</div>

Traceback return the following

 ![Traceback](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/8/8ee337a666a1393a720fcac5afaccd7ec5bc54bf.png)

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [October 11, 2018, 4:30am UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/5 "2018-10-11T04:30:11Z")

</div>

If you do `require(rstan)` instead of `library(rstan)` does it give you anything different?

---

<div class="post-metadata">

**Author:** ![Potanin](https://avatars.discourse-cdn.com/v4/letter/p/a698b9/32.png) [@Potanin](https://discourse.mc-stan.org/u/Potanin)\
**Post date:** [October 11, 2018, 10:21am UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/6 "2018-10-11T10:21:33Z")

</div>

It gives the same error message.

Загрузка требуемого пакета: rstan  
Загрузка требуемого пакета: ggplot2  
Загрузка требуемого пакета: StanHeaders  
Error: package or namespace load failed for ‘rstan’ in rbind(info, getNamespaceInfo(env, “S3methods”)):  
number of columns of matrices must match (see arg 2)  
Warning message:  
пакет ‘rstan’ был собран под R версии 3.6.0

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [October 12, 2018, 11:41pm UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/7 "2018-10-12T23:41:46Z")

</div>

OK. Maybe do `remove.packages("rstan")`, restart R cleanly, do `install.packages("rstan")` but then put

```
CXX14 = g++ -std=c++1y
CXX14FLAGS = -O3 -Wno-unused-variable -Wno-unused-function

```

into your ~/.R/Makevars file before trying to compile any Stan models.

---

<div class="post-metadata">

**Author:** ![Potanin](https://avatars.discourse-cdn.com/v4/letter/p/a698b9/32.png) [@Potanin](https://discourse.mc-stan.org/u/Potanin)\
**Post date:** [October 20, 2018, 8:07am UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/8 "2018-10-20T08:07:10Z")

</div>

Hello, Ben!

Sorry for nonresponding for so loing as I was extremely bussy.

I made these steps but then I get the following message:

Error in compileCode(f, code, language = language, verbose = verbose) :  
Compilation ERROR, function(s)/method(s) not created! C:/R/R-3.5.1/library/StanHeaders/libs/x64/StanHeaders.dll: file not recognized: File format not recognized  
collect2.exe: error: ld returned 1 exit status  
In addition: Warning message:  
In readLines(file, warn = TRUE) :  
incomplete final line found on ‘D:\Р’РЁР­\3 РєСѓСЂСЃ\РЎРѕРЅСЏ\8schools.stan’

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [October 20, 2018, 2:33pm UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/9 "2018-10-20T14:33:28Z")

</div>

If `cat(strsplit(Sys.getenv(“PATH”), “;”)[[1]], sep = “\n”)` shows anything pertaining to mingw\_32 (which appears likely), then you need to remove it from your PATH using something like

> [@Compilation ERROR - brms and stan model](https://discourse.mc-stan.org/t/compilation-error-brms-and-stan-model/6006/42):
>
> OK, according to @paul.buerkner , the problem is the presence of C:\Rtools\mingw\_32\bin in your PATH. To delete this, click something like left-click on Start right-click on Computer left-click on Properties left-click on Advanced System Settings left-click on Environmental variables scroll down in the bottom window to Path and left-click it left-click Edit move the cursor all the way to the left then delete the part that says C:\Rtools\mingw\_32\bin; (be sure to delete exactly one semi-colon) l…

---

<div class="post-metadata">

**Author:** ![Potanin](https://avatars.discourse-cdn.com/v4/letter/p/a698b9/32.png) [@Potanin](https://discourse.mc-stan.org/u/Potanin)\
**Post date:** [October 21, 2018, 8:55pm UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/10 "2018-10-21T20:55:06Z")

</div>

Thank you for detailed steps! I has been following them carefully. And I get 10. However, I still get the error when trying to build a model:

Error in compileCode(f, code, language = language, verbose = verbose) :  
Compilation ERROR, function(s)/method(s) not created! g++: not found  
make: \*\*\* [file20246b3242fb.o] Error 127  
In addition: Warning messages:  
1: In readLines(file, warn = TRUE) :  
incomplete final line found on ‘D:\Р’РЁР­\3 РєСѓСЂСЃ\РЎРѕРЅСЏ\8schools.stan’  
2: In system(cmd, intern = !verbose) :  
running command ‘C:/R/R-35~1.1/bin/x64/R CMD SHLIB file20246b3242fb.cpp 2\> file20246b3242fb.cpp.err.txt’ had status 1

My path looks like ![Rtools](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/c/c870dfb91e631ea4cdfaed787e80e61e9e0e0553.png)

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [October 21, 2018, 9:30pm UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/11 "2018-10-21T21:30:47Z")

</div>

You should uninstall Rtools 3.4 and then make sure your path has nothing pertaining to `mingw_32` or `mingw_64`. Once you do that, you can also try

```
pkgbuild::has_build_tools(debug = TRUE)

```

---

<div class="post-metadata">

**Author:** ![Potanin](https://avatars.discourse-cdn.com/v4/letter/p/a698b9/32.png) [@Potanin](https://discourse.mc-stan.org/u/Potanin)\
**Post date:** [October 21, 2018, 10:03pm UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/12 "2018-10-21T22:03:15Z")

</div>

> [@bgoodri](#):
>
> pkgbuild::has\_build\_tools(debug = TRUE)

I made these steps and the commant returns TRUE. But the error reamins the same when I am building the model.

---

<div class="post-metadata">

**Author:** ![Potanin](https://avatars.discourse-cdn.com/v4/letter/p/a698b9/32.png) [@Potanin](https://discourse.mc-stan.org/u/Potanin)\
**Post date:** [November 2, 2018, 5:54pm UTC](https://discourse.mc-stan.org/t/r-stan-compilation-error-possibly-related-to-c-14/5947/13 "2018-11-02T17:54:21Z")

</div>

I have totally reinstalled all R related stuff following new installation guide [https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Windows](https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Windows)

Now all works greate! Thank you very much for your exensive help!

P.S. While installing R-tools I made my path look exactly like tutorial ones removeing all other rows.
