Error compiling stan

I have tried to run my model with brms and this is the error that I get, I am a first-time user, and I am not sure how to troubleshoot this!
##############################
setwd(“D:/DESKTOP/UCT 2023/R-Final”)

library(ProbBayes)
Loading required package: LearnBayes

Attaching package: ‘LearnBayes’

The following object is masked from ‘package:brms’:

rdirichlet

Loading required package: gridExtra
Loading required package: shiny

library(brms)
library(dplyr)

Attaching package: ‘dplyr’

The following object is masked from ‘package:gridExtra’:

combine

The following objects are masked from ‘package:stats’:

filter, lag

The following objects are masked from ‘package:base’:

intersect, setdiff, setequal, union

library(ggplot2)
practc ← read.csv(“D:/DESKTOP/UCT 2023/R-Final/Imputedpaxdata_CatData.csv”)
colnames(practc) ← c(‘Age’,‘Gender’,‘Education’, ‘NtIndvIncm’, ‘DaysWkMBT’, ‘DlyTxFare’, ‘PrevCFCUse’, ‘CFCPref’)
PracticeBRMS ← practc
#non-informative priors2
fit_CFC_pref ← brm(CFCPref~ Age + Gender + Education + NtIndvIncm + DaysWkMBT + DlyTxFare

  •                 + PrevCFCUse, data = PracticeBRMS, family = Gamma("log"))
    

Compiling Stan program…
make cmd is
make -f “C:/PROGRA~1/R/R-43~1.1/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-43~1.1/share/make/winshlib.mk” CXX=‘(CXX14) (CXX14STD)’ CXXFLAGS=‘(CXX14FLAGS)' CXXPICFLAGS='(CXX14PICFLAGS)’ SHLIB_LDFLAGS=‘(SHLIB_CXX14LDFLAGS)' SHLIB_LD='(SHLIB_CXX14LD)’ SHLIB=“file14504c8a6ca0.dll” WIN=64 TCLBIN= OBJECTS=“file14504c8a6ca0.o”

make would use
if test “zfile14504c8a6ca0.o” != “z”; then
if test -e “file14504c8a6ca0-win.def”; then
echo g++ -shared -s -static-libgcc -o file14504c8a6ca0.dll file14504c8a6ca0-win.def file14504c8a6ca0.o -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ;
g++ -shared -s -static-libgcc -o file14504c8a6ca0.dll file14504c8a6ca0-win.def file14504c8a6ca0.o -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ;
else
echo EXPORTS > tmp.def;
nm file14504c8a6ca0.o | sed -n ‘s/^.* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed ‘s/[^ ][^ ]*/“&”/g’ >> tmp.def;
echo g++ -shared -s -static-libgcc -o file14504c8a6ca0.dll tmp.def file14504c8a6ca0.o -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ;
g++ -shared -s -static-libgcc -o file14504c8a6ca0.dll tmp.def file14504c8a6ca0.o -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-43~1.1/bin/x64" -lR ;
rm -f tmp.def;
fi
fi
Error in compileCode(f, code, language = language, verbose = verbose) :
C:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\bin/ld.exe: file14504c8a6ca0.o:file14504c8a6ca0.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1c): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\bin/ld.exe: file14504c8a6ca0.o:file14504c8a6ca0.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1c): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\bin/ld.exe: file14504c8a6ca0.o:file14504c8a6ca0.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x37): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\bin/ld.exe: file14504c8a6ca0.o:file14504c8a6ca0.c
Error in sink(type = “output”) : invalid connection
##############################

Thanks,
Aruho

Dear Aruho, hi again. Thanks for posting on the forum as requested.

If I recall correctly, on your last update you mentioned you had installed the latest development version of rstan.

Can you please start a fresh session in the folder you are working at and run this command: packageVersion("rstan"), then let me know the result and we can continue from there.

1 Like

Dear BMFazio,

Thank you for the follow-up. I very much appreciate your assistance.
It magically worked on Monday; I hesitated to celebrate and come here with the good news.
Today, as I tried to work on my model, it again brought the same Error.

My question, now, is: must I go through installing ‘cmdstan’ every time I want to do a Bayesian regression with brms?

Aruho.

In principle, installing cmdstanr once should make the models run from that point on, provided you actually tell brms that you wish to use that as a backend. Because, by default, brms uses the rstan backend, it will keep causing the same crash.

If you run this example in a new session, it should cause the crash:

library(brms)
fit1 <- brm(count ~ zAge,
            data = epilepsy, family = poisson())

But once you specify you want to use the cmdstanr backend as part of the function call, it should not:

library(brms)
fit1 <- brm(count ~ zAge,
            data = epilepsy, family = poisson(), backend = "cmdstanr")

Let me know if that resolves your issue.

Dear Fazio,
Thank you so much for your consistency and helping out.
I ran my model, and it came out great.
I think the last option you have given is what worked for me.
You had given me the backend option with cmdstan and it is what I triggered- though unknowingly, and it worked!
Your explanation now justifies my actions.

Thank you.
Aruho

1 Like