# Error in compileCode()

**URL:** <https://discourse.mc-stan.org/t/error-in-compilecode/16940>\
**Category:** Interfaces\
**Tags:** rstan\
**Created:** [July 23, 2020, 10:13pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/16940 "2020-07-23T22:13:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![avdminne](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@avdminne](https://discourse.mc-stan.org/u/avdminne)\
**Post date:** [July 23, 2020, 10:13pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/16940/1 "2020-07-23T22:13:46Z")

</div>

Dear all,

I get the following error - while running a stan model - after I updated R to 4.02. (Which I regret now…)

```
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: filec6c78d428af.o:filec6c78d428af.cpp:(.text+0x132c): undefined reference to `rstan::stan_fit::stan_fit(SEXPREC*, int)'
C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: filec6c78d428af.o:filec6c78d428af.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D1Ev[_ZN3tbb8internal26task_scheduler_observer_v3D1Ev]+0x14): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: filec6c78d428af.o:filec6c78d428af.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
C:/rtools40/mingw64/bin/../lib/gcc/x86_64
In addition: Warning message:
In file.remove(c(unprocessed, processed)) :
  cannot remove file 'C:\Users\avdminne\AppData\Local\Temp\Rtmp2RBKKS\filec6c6f41831.stan', reason 'No such file or directory'
Error in sink(type = "output") : invalid connection

```

It ran fine before the update. I did re-install Rtools to the latest version as well.

```
pkgbuild::has_build_tools(debug = TRUE)
[1] TRUE

devtools::session_info("rstan")
- Session info ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 setting value                       
 version R version 4.0.2 (2020-06-22)
 os Windows 10 x64              
 system x86_64, mingw32             
 ui RStudio                     
 language (EN)                        
 collate English_United States.1252  
 ctype English_United States.1252  
 tz America/New_York            
 date 2020-07-23                  

- Packages --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 ! package * version date lib source        
   assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.2)
   backports 1.1.7 2020-05-13 [1] CRAN (R 4.0.0)
   BH 1.72.0-3 2020-01-08 [1] CRAN (R 4.0.0)
   callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.2)
   checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.2)
   cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.2)
   colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.2)
   crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.2)
   curl 4.3 2019-12-02 [1] CRAN (R 4.0.2)
   desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.2)
   digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.2)
   ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.2)
   evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.2)
   fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.2)
   farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.2)
   ggplot2 * 3.3.2 2020-06-19 [1] CRAN (R 4.0.2)
   glue 1.4.1 2020-05-13 [1] CRAN (R 4.0.2)
   gridExtra 2.3 2017-09-09 [1] CRAN (R 4.0.2)
   gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.2)
   inline 0.3.15 2018-05-18 [1] CRAN (R 4.0.2)
   isoband 0.2.2 2020-06-20 [1] CRAN (R 4.0.2)
   jsonlite 1.7.0 2020-06-25 [1] CRAN (R 4.0.2)
   labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0)
   lattice * 0.20-41 2020-04-02 [2] CRAN (R 4.0.2)
   lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.2)
   loo * 2.3.1 2020-07-14 [1] CRAN (R 4.0.2)
   magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.2)
   MASS 7.3-51.6 2020-04-26 [2] CRAN (R 4.0.2)
   Matrix 1.2-18 2019-11-27 [2] CRAN (R 4.0.2)
   matrixStats 0.56.0 2020-03-13 [1] CRAN (R 4.0.2)
   mgcv 1.8-31 2019-11-09 [2] CRAN (R 4.0.2)
   munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.2)
   nlme 3.1-148 2020-05-24 [2] CRAN (R 4.0.2)
   pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.2)
   pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 4.0.2)
   pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.2)
   pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.2)
   praise 1.0.0 2015-08-11 [1] CRAN (R 4.0.2)
   prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.2)
   processx 3.4.3 2020-07-05 [1] CRAN (R 4.0.2)
   ps 1.3.3 2020-05-08 [1] CRAN (R 4.0.2)
   R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.2)
   RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.0)
   Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.2)
   RcppEigen 0.3.3.7.0 2019-11-16 [1] CRAN (R 4.0.2)
 D RcppParallel 5.0.2 2020-06-24 [1] CRAN (R 4.0.2)
   rlang 0.4.7 2020-07-09 [1] CRAN (R 4.0.2)
   rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.2)
   rstan * 2.21.1 2020-07-08 [1] CRAN (R 4.0.2)
   rstudioapi * 0.11 2020-02-07 [1] CRAN (R 4.0.2)
   scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.2)
   StanHeaders * 2.21.0-5 2020-06-09 [1] CRAN (R 4.0.2)
   testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.2)
   tibble 3.0.3 2020-07-10 [1] CRAN (R 4.0.2)
   utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.2)
   V8 3.2.0 2020-06-19 [1] CRAN (R 4.0.2)
   vctrs 0.3.2 2020-07-15 [1] CRAN (R 4.0.2)
   viridisLite 0.3.0 2018-02-01 [1] CRAN (R 4.0.2)
   withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.2)

[1] C:/Users/avdminne/Documents/ListPrice/Packages
[2] C:/Program Files/R/R-4.0.2/library

 D -- DLL MD5 mismatch, broken installation.

```

I have seen some similar topics on this forum, but non of the suggestions there seem to solve it for me. (Like re-installing stan and StanHeaders from the source, etc.)  
Does anyone have a clue as to why stan refuses to run all of a sudden? Running stan with VERBOSE = TRUE doesn’t really help me that much, but let me know if you need that.

Many thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [July 23, 2020, 11:01pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/16940/2 "2020-07-23T23:01:03Z")

</div>

Hey Alex, sorry for the hassle.

> [@avdminne](#):
>
> (Like re-installing stan and StanHeaders from the source, etc.)

What about installing from binary and not source using the links from this post:

> [@Error in file(con, "r") : invalid 'description' argument](https://discourse.mc-stan.org/t/error-in-file-con-r-invalid-description-argument/16831/10):
>
> @Chiraz_BenAbdelkader Can you try installing from these updated links install.packages( "https://artifacts.r-hub.io/StanHeaders\_2.21.0-6.tar.gz-5af2069f840e9b971ee5b0e175da5ea6/StanHeaders\_2.21.0-6.zip", repos = NULL, type = "win.binary") install.packages( "https://artifacts.r-hub.io/rstan\_2.21.2.tar.gz-3145e4a7fcd4016d378efd0e537d8b91/rstan\_2.21.2.zip", repos = NULL, type = "win.binary") and let us know if you still get errors? Thanks! Edit: these are the same links as the updated links in t…

---

<div class="post-metadata">

**Author:** ![avdminne](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@avdminne](https://discourse.mc-stan.org/u/avdminne)\
**Post date:** [July 26, 2020, 5:51pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/16940/3 "2020-07-26T17:51:54Z")

</div>

I Jonah,

many thanks for the quick response! I got it to work on my laptop, but not so much on my desktop yet. I think it has to do with the Makevars “thing”. In all honesty, I have seen that “thing”’ come up multiple times on this forum, but I have no idea what it does or how it exactly works. Do you know what the exact steps are?

```
file.edit("~/.R/Makevars.win")

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

```

My understanding is that I delete every line that has the `-march=native -mtune=native` in it? And subsequently save the new file? Is that it?

Again, thank you very much.  
Alex

---

<div class="post-metadata">

**Author:** ![avdminne](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@avdminne](https://discourse.mc-stan.org/u/avdminne)\
**Post date:** [July 26, 2020, 6:10pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/16940/4 "2020-07-26T18:10:27Z")

</div>

Wait, upon closer inspection, the link to rstan is probably updated in the meantime.  
Was in time with my laptop, but apparently not with my desktop. I noticed someone else had the same issue;

> [@Error in compileCode(f, code, language = language, verbose = verbose) & 'No such file or directory' error](https://discourse.mc-stan.org/t/error-in-compilecode-f-code-language-language-verbose-verbose-no-such-file-or-directory-error/16979):
>
> Hi, I am pretty new to Stan. I have been trying to run the schools.stan model example, but I am always getting a list of Errors. Similar issues in the forums have not been helpful for me yet. These are my software versions: Windows 10 RStan version: 2.21.1 StanHeaders: 2.21.0-5 RStudio version: 4.0.2 RTools version: 4.0.0.28 When I run: example(stan\_model, run.dontrun = TRUE) I get this output: Fehler in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR,…

I keep an eye out for that post. Still, I would be interested in getting to know the Makevars procedure a bit better. Could you recommend some further reading for example?  
Alex

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [July 27, 2020, 6:05pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/16940/5 "2020-07-27T18:05:59Z")

</div>

> [@avdminne](#):
>
> I would be interested in getting to know the Makevars procedure a bit better. Could you recommend some further reading for example?

I think it’s confusing for everyone ;) I wish I had a good resource to point to but I’m not sure. Basically `Makevars` is a file where you can specify options for compilers. The official resource from CRAN is

> **[Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Using-Makevars)**
>
> Writing R Extensions

but I don’t find that to be particularly educational unfortunately!

Did you end up getting it running on your desktop? I think with the version of rstan available at the links in my previous post, you can get away with deleting everything from the Makevars file. @bgoodri @stevebronder is that right?

---

<div class="post-metadata">

**Author:** ![avdminne](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@avdminne](https://discourse.mc-stan.org/u/avdminne)\
**Post date:** [July 27, 2020, 8:03pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/16940/6 "2020-07-27T20:03:23Z")

</div>

> [@jonah](#):
>
> had

I am able to download rstan now via the link. Unfortunately, I get the following error message now;

```no-highlight
Error in stan_model(file, model_name = model_name, model_code = model_code, : 
  Boost not found; call install.packages('BH')

```

To state the obvious, BH is installed. I did notice one other earlier message mentioning the same issue;

> [@8schools error Boost not found](https://discourse.mc-stan.org/t/8schools-error-boost-not-found/1719):
>
> Greetings, I am getting started with RStan and I get the following error while running the basic example 8schools.stan: Error in stan\_model(file, model\_name = model\_name, model\_code = model\_code, : Boost not found; call install.packages(‘BH’) BH (1.65) is installed and loaded. However I came across this other post and wonder if it could be related. rstan compilation error under Boost 1.64 #441 Any help will be greatly appreciated, Cheers! Here is my session info: sessionInfo() R vers…

However, the solution in that post was to simply restart R. That doesn’t work for me…  
Sorry for the many questions. I have been using Stan for years now, and only recently has it started to give me issues that I have never had before.  
Alex

---

<div class="post-metadata">

**Author:** ![avdminne](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@avdminne](https://discourse.mc-stan.org/u/avdminne)\
**Post date:** [July 27, 2020, 8:19pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/16940/7 "2020-07-27T20:19:12Z")

</div>

Ignore my previous message. After restarting my entire PC, it did work!  
Many thanks, finally back to Stan.

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [July 27, 2020, 8:50pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/16940/8 "2020-07-27T20:50:25Z")

</div>

Sorry for the hassle, but glad it’s working now!
