Error running Stan Model with rstan 2.21 and R 4.0.2

I’m learning abou Stan and started watching videos on internet. But all of my tries failed, because of this same error:

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: file32186dc1e8a.o:file32186dc1e8a.cpp:(.text+0x74c): 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: file32186dc1e8a.o:file32186dc1e8a.cpp:(.text+0x11b7): 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: file32186dc1e8a.o:file32186dc1e8a.cpp:(.text+0x78e): 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: file32186dc1e8a.o:file32186dc1e8a.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D1Ev[_ZN3tbb8internal26task_scheduler_observe
In addition: Warning message:
In file.remove(c(unprocessed, processed)) :
  cannot remove file 'C:\Users\loren\AppData\Local\Temp\RtmpYlpMbb\file321864fc4d42.stan', reason 'No such file or directory'

Start with

but there may be more things to follow up with.

1 Like

Thanks !!!

This worked for my model, but I have a sample problem including a “generated quantity”.
The message “Stan model ‘third_model’ does not contain samples” show.

generated quantities {
  vector[n_new] y_new;
  for (t in 1:n_new){
    y_new[t]=normal_rng(l[t-1]+b[t-1], sigma);
  }
}

Is there more to the message than just “Stan model ‘third_model’ does not contain samples”? It’s hard to tell from just that if there’s an issue with the model or an issue with the installation.