# Error in compileCode

**URL:** <https://discourse.mc-stan.org/t/error-in-compilecode/32409>\
**Category:** RStan\
**Tags:** rstan, fitting-issues\
**Created:** [August 10, 2023, 1:59am UTC](https://discourse.mc-stan.org/t/error-in-compilecode/32409 "2023-08-10T01:59:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yinzhu0199](https://avatars.discourse-cdn.com/v4/letter/y/97f17d/32.png) [@yinzhu0199](https://discourse.mc-stan.org/u/yinzhu0199)\
**Post date:** [August 10, 2023, 1:59am UTC](https://discourse.mc-stan.org/t/error-in-compilecode/32409/1 "2023-08-10T01:59:24Z")

</div>

Hi there,

I am new to Rstan, I installed the Rstan packages and tried to fit a model. An compileCode error popped up and I cannot solve it even after trying many suggested solutions from Rstan website.

Could anyone help me?

Code I ran:

```plaintext
remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")

#Sys.setenv(DOWNLOAD_STATIC_LIBV8 = 1) # only necessary for Linux without the nodejs library / headers
install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)

#Sys.setenv(MAKEFLAGS = paste0("-j",parallel::detectCores()))
remove.packages("rstan") 
install.packages("rstan",type="source")

remove.packages(c("StanHeaders","rstan")) 
install.packages(c("StanHeaders","rstan"),type="source")

library(rstan)
library(StanHeaders)
library(ggplot2)
options(mc.cores = parallel::detectCores()) # Make use of multiple cores if available
rstan_options(auto_write = TRUE) # If the Stan model does not change, don't recompile

set.seed(1234)
Pois_data <- rpois(500, 3) # Generate Poisson Data
mean(Pois_data)

fit<-stan(file = "poisson_gamma.stan", data = list(y = Pois_data, N = length(Pois_data)), iter = 500, seed = 10)

```

The error message I got:  
Error in compileCode(f, code, language = language, verbose = verbose) :  
C:\Users\yzhu\Downloads\R\_Files\rtools43\x86\_64-w64-mingw32.static.posix\bin/ld.exe: file3dc47d8f6b35.o:file3dc47d8f6b35.cpp:(.text$\_ZN3tbb8internal26task\_scheduler\_observer\_v3D0Ev[\_ZN3tbb8internal26task\_scheduler\_observer\_v3D0Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\Users\yzhu\Downloads\R_Files\rtools43\x86_64-w64-mingw32.static.posix\bin/ld.exe: file3dc47d8f6b35.o:file3dc47d8f6b35.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1c): undefined reference to `tbb::internal::task\_scheduler\_observer\_v3::observe(bool)'C:\Users\yzhu\Downloads\R\_Files\rtools43\x86\_64-w64-mingw32.static.posix\bin/ld.exe: file3dc47d8f6b35.o:file3dc47d8f6b35.cpp:(.text$\_ZN3tbb10interface623task\_scheduler\_observerD1Ev[\_ZN3tbb10interface623task\_scheduler\_observerD1Ev]+0x37): undefined reference to `tbb::internal::task\_scheduler\_observer\_v3::observe(bool)'C:\Users\yzhu\Downloads\R\_Files\rt  
Error in sink(type = “output”) : invalid connection

- Operating System: Windows 10 Enterprise
- R version: 4.3.1
- Rtools version: rtools43

Thank you so much for any help!!!

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [August 14, 2023, 9:18am UTC](https://discourse.mc-stan.org/t/error-in-compilecode/32409/2 "2023-08-14T09:18:46Z")

</div>

See the Getting Started guide: [Configuring C Toolchain for Windows · stan-dev/rstan Wiki · GitHub](https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Windows#r-43)
