# Problems with rstan::stan\_model

**URL:** <https://discourse.mc-stan.org/t/problems-with-rstan-stan-model/32320>\
**Category:** RStan\
**Tags:** rstan\
**Created:** [August 2, 2023, 2:38am UTC](https://discourse.mc-stan.org/t/problems-with-rstan-stan-model/32320 "2023-08-02T02:38:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthony\_econ](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@anthony\_econ](https://discourse.mc-stan.org/u/anthony_econ)\
**Post date:** [August 2, 2023, 2:38am UTC](https://discourse.mc-stan.org/t/problems-with-rstan-stan-model/32320/1 "2023-08-02T02:38:39Z")

</div>

So I am currently running this code in R.

use\_data ← au.data[au.data$date \>=“1983-03-31”,]

> au.inflation ← use\_data$inflation  
> au.inflation.expectations ← use\_data$inflation.expectations  
> au.labour.costs.growth ← use\_data$labour.costs.growth  
> au.unemployment ← use\_data$unemployment  
> au.imports.price.growth ← use\_data$imports.price.growth  
> au.oil.price.change ← use\_data$oil.price.change  
> au.dummy ← use\_data$dummy  
> N ← length(au.unemployment)  
> stancode ← rstan::stan\_model(“nairu\_model.stan”, verbose = FALSE)

However, when I run the last line I get a bunch of errors as follows:  
make cmd is  
make -f “C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/etc/x64/Makeconf” -f “C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/share/make/winshlib.mk” -f “C:/Users/AnthonyM/OneDrive/Documents/.R/Makevars.win” CXX=‘(CXX14) (CXX14STD)’ CXXFLAGS=‘(CXX14FLAGS)' CXXPICFLAGS='(CXX14PICFLAGS)’ SHLIB\_LDFLAGS=‘(SHLIB\_CXX14LDFLAGS)' SHLIB\_LD='(SHLIB\_CXX14LD)’ SHLIB=“file2ce02a17e32.dll” WIN=64 TCLBIN= OBJECTS=“file2ce02a17e32.o”

make would use  
if test “zfile2ce02a17e32.o” != “z”; then   
if test -e “file2ce02a17e32-win.def”; then   
echo g++ -std=c++1y -shared -s -static-libgcc -o file2ce02a17e32.dll file2ce02a17e32-win.def file2ce02a17e32.o -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib" -L"C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/bin/x64" -lR ;   
g++ -std=c++1y -shared -s -static-libgcc -o file2ce02a17e32.dll file2ce02a17e32-win.def file2ce02a17e32.o -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib" -L"C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/bin/x64" -lR ;   
else   
echo EXPORTS \> tmp.def;   
C:/RBuildTools/4.2/mingw64/bin/nm file2ce02a17e32.o | sed -n ‘s/^.\* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed ‘s/[^][^]\*/“&”/g’ \>\> tmp.def;   
echo g++ -std=c++1y -shared -s -static-libgcc -o file2ce02a17e32.dll tmp.def file2ce02a17e32.o -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib" -L"C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/bin/x64" -lR ;   
g++ -std=c++1y -shared -s -static-libgcc -o file2ce02a17e32.dll tmp.def file2ce02a17e32.o -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib" -L"C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/bin/x64" -lR ;   
rm -f tmp.def;   
fi   
fi

Note I have the latest Rstan and StanHeaders package. Do you guys have any idea why this could be happening?

---

<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 2, 2023, 7:39am UTC](https://discourse.mc-stan.org/t/problems-with-rstan-stan-model/32320/2 "2023-08-02T07:39:05Z")

</div>

Can you post the full output from running:

```r
example(stan_model, package="rstan", run.dontrun=T)

```

---

<div class="post-metadata">

**Author:** ![anthony\_econ](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@anthony\_econ](https://discourse.mc-stan.org/u/anthony_econ)\
**Post date:** [August 2, 2023, 9:34pm UTC](https://discourse.mc-stan.org/t/problems-with-rstan-stan-model/32320/3 "2023-08-02T21:34:14Z")

</div>

Sure, see below the output from running the following code:

Compilation ERROR, function(s)/method(s) not created!  
Error in compileCode(f, code, language = language, verbose = verbose) :  
C:\rtools43\x86\_64-w64-mingw32.static.posix\bin/ld.exe: file50082add5b74.o:file50082add5b74.cpp:(.text$\_ZN3tbb8internal26task\_scheduler\_observer\_v3D0Ev[\_ZN3tbb8internal26task\_scheduler\_observer\_v3D0Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools43\x86_64-w64-mingw32.static.posix\bin/ld.exe: file50082add5b74.o:file50082add5b74.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1c): undefined reference to `tbb::internal::task\_scheduler\_observer\_v3::observe(bool)'C:\rtools43\x86\_64-w64-mingw32.static.posix\bin/ld.exe: file50082add5b74.o:file50082add5b74.cpp:(.text$\_ZN3tbb10interface623task\_scheduler\_observerD1Ev[\_ZN3tbb10interface623task\_scheduler\_observerD1Ev]+0x37): undefined reference to `tbb::internal::task\_scheduler\_observer\_v3::observe(bool)'C:\rtools43\x86\_64-w64-mingw32.static.posix\bin/ld.exe: file50082add5b74.o:file50082add5b74.cpp:(.text$\_ZN3tbb10interface

Bit confused what is going on here.

---

<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 2, 2023, 10:09pm UTC](https://discourse.mc-stan.org/t/problems-with-rstan-stan-model/32320/4 "2023-08-02T22:09:31Z")

</div>

Try reinstalling from source:

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

```

---

<div class="post-metadata">

**Author:** ![anthony\_econ](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@anthony\_econ](https://discourse.mc-stan.org/u/anthony_econ)\
**Post date:** [August 2, 2023, 10:44pm UTC](https://discourse.mc-stan.org/t/problems-with-rstan-stan-model/32320/5 "2023-08-02T22:44:12Z")

</div>

Tried this and reran the following:

stancode ← rstan::stan\_model(“nairu\_model.stan”, verbose = FALSE)  
make cmd is  
make -f “C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/etc/x64/Makeconf” -f “C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/share/make/winshlib.mk” -f “C:/Users/AnthonyM/OneDrive/Documents/.R/Makevars.win” CXX=‘(CXX14) (CXX14STD)’ CXXFLAGS=‘(CXX14FLAGS)' CXXPICFLAGS='(CXX14PICFLAGS)’ SHLIB\_LDFLAGS=‘(SHLIB\_CXX14LDFLAGS)' SHLIB\_LD='(SHLIB\_CXX14LD)’ SHLIB=“file1cfc137462.dll” WIN=64 TCLBIN= OBJECTS=“file1cfc137462.o”

make would use  
if test “zfile1cfc137462.o” != “z”; then   
if test -e “file1cfc137462-win.def”; then   
echo g++ -std=c++1y -shared -s -static-libgcc -o file1cfc137462.dll file1cfc137462-win.def file1cfc137462.o -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib" -L"C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/bin/x64" -lR ;   
g++ -std=c++1y -shared -s -static-libgcc -o file1cfc137462.dll file1cfc137462-win.def file1cfc137462.o -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib" -L"C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/bin/x64" -lR ;   
else   
echo EXPORTS \> tmp.def;   
C:/RBuildTools/4.2/mingw64/bin/nm file1cfc137462.o | sed -n ‘s/^.\* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed ‘s/[^][^]\*/“&”/g’ \>\> tmp.def;   
echo g++ -std=c++1y -shared -s -static-libgcc -o file1cfc137462.dll tmp.def file1cfc137462.o -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib" -L"C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/bin/x64" -lR ;   
g++ -std=c++1y -shared -s -static-libgcc -o file1cfc137462.dll tmp.def file1cfc137462.o -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86\_64-w64-mingw32.static.posix/lib" -L"C:/Users/AnthonyM/AppData/Local/Programs/R/R-43~1.1/bin/x64" -lR ;   
rm -f tmp.def;   
fi   
fi  
Error in compileCode(f, code, language = language, verbose = verbose) :  
C:\rtools43\x86\_64-w64-mingw32.static.posix\bin/ld.exe: file1cfc137462.o:file1cfc137462:(.text$\_ZN3tbb8internal26task\_scheduler\_observer\_v3D0Ev[\_ZN3tbb8internal26task\_scheduler\_observer\_v3D0Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools43\x86_64-w64-mingw32.static.posix\bin/ld.exe: file1cfc137462.o:file1cfc137462:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1c): undefined reference to `tbb::internal::task\_scheduler\_observer\_v3::observe(bool)'C:\rtools43\x86\_64-w64-mingw32.static.posix\bin/ld.exe: file1cfc137462.o:file1cfc137462:(.text$\_ZN3tbb10interface623task\_scheduler\_observerD1Ev[\_ZN3tbb10interface623task\_scheduler\_observerD1Ev]+0x37): undefined reference to `tbb::internal::task\_scheduler\_observer\_v3::observe(bool)'C:\rtools43\x86\_64-w64-mingw32.static.posix\bin/ld.exe: file1cfc137462.o:file1cfc137462:(.text$_ZN3tbb10interface623task\_scheduler\_observerD0Ev[_  
Error in sink(type = “output”) : invalid connection

>

---

<div class="post-metadata">

**Author:** ![anthony\_econ](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@anthony\_econ](https://discourse.mc-stan.org/u/anthony_econ)\
**Post date:** [August 2, 2023, 11:20pm UTC](https://discourse.mc-stan.org/t/problems-with-rstan-stan-model/32320/6 "2023-08-02T23:20:58Z")

</div>

NOTE, after installing from the source (older version) and then reupdating to the newer version the stan\_model code works now!

THANKS! :)
