Error related to the Threading Building Blocks (TBB) library

I am getting this error, I tried to solve it but with no success.
Any help?

make cmd is
  make -f "C:/PROGRA~1/R/R-42~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-42~1.3/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file3b70308869d4.dll" WIN=64 TCLBIN= OBJECTS="file3b70308869d4.o"

make would use
if test "zfile3b70308869d4.o" != "z"; then \
  if test -e "file3b70308869d4-win.def"; then \
    echo g++  -shared -s -static-libgcc -o file3b70308869d4.dll file3b70308869d4-win.def file3b70308869d4.o  -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib"  -L"C:/PROGRA~1/R/R-42~1.3/bin/x64" -lR ; \
    g++  -shared -s -static-libgcc -o file3b70308869d4.dll file3b70308869d4-win.def file3b70308869d4.o  -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib"  -L"C:/PROGRA~1/R/R-42~1.3/bin/x64" -lR ; \
  else \
    echo EXPORTS > tmp.def; \
    nm file3b70308869d4.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 file3b70308869d4.dll tmp.def file3b70308869d4.o  -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib"  -L"C:/PROGRA~1/R/R-42~1.3/bin/x64" -lR ; \
    g++  -shared -s -static-libgcc -o file3b70308869d4.dll tmp.def file3b70308869d4.o  -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib"  -L"C:/PROGRA~1/R/R-42~1.3/bin/x64" -lR ; \
    rm -f tmp.def; \
  fi \
fi
Error in compileCode(f, code, language = language, verbose = verbose) : 
  C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file3b70308869d4.o:file3b70308869d4.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file3b70308869d4.o:file3b70308869d4.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file3b70308869d4.o:file3b70308869d4.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file3b70308869d4.o:file3b70308869d4.cpp:(.text$_ZN3tbb10interface
Error in sink(type = "output") : invalid connection
> 

Operating System: Windows 11
Interface Version:
RStudio 2023.03.0+386 “Cherry Blossom” Release (3c53477afb13ab959aeb5b34df1f10c237b256c3, 2023-03-09) for Windows
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2023.03.0+386 Chrome/108.0.5359.179 Electron/22.0.3 Safari/537.36

I followed all steps from:

All worked great, up to here:
If the example model fails with the error:
“Error in compileCode(f, code, language = language, verbose = verbose) :
C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_6”

I did this:
Then restart R and reinstall rstan and StanHeaders from source:

Compile packages using all cores Sys.setenv(MAKEFLAGS = paste0(“-j”,parallel::detectCores())) install.packages(c(“StanHeaders”,“rstan”),type=“source”)

But it still does not work. Many thanks for your help!

See the Getting Started guide

Thank you for replying.

image

All went well up to this point. I did the procedure above, but I am still getting this error.

After run this:
image

I am obtain:

Did the preview versions of rstan and StanHeaders install successfully? What is your output from:

packageVersion("StanHeaders")
packageVersion("rstan")

It did not:
image

After:
image

I got:

Note that I’m not referring to installing the packages from source. The instructions I linked to said:

What happens when you try this?

You saved my day! It worked.

End line from test:

Thank you very much!

I have installed Rtools 4.0. It should work fine with:
image

Correct? Thanks