But it fails when called from RStudio (Version 2026.01.1+403, R version 4.5.3):
Chain 1 dyld[19146]: Library not loaded: @rpath/libtbb.12.dylib
Chain 1 Referenced from: <FB21BB72-06DB-3B16-913C-A4A70C56E763> /Users/edelaire1/.cmdstan/cmdstan-2.38.0/examples/bernoulli/bernoulli
Chain 1 Reason: tried: '/Users/edelaire1/.cmdstan/cmdstan-2.38.0/stan/lib/stan_math/lib/tbb/libtbb.12.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/edelaire1/.cmdstan/cmdstan-2.38.0/stan/lib/stan_math/lib/tbb/libtbb.12.dylib' (no such file), '/Users/edelaire1/.cmdstan/cmdstan-2.38.0/stan/lib/stan_math/lib/tbb/libtbb.12.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/edelaire1/.cmdstan/cmdstan-2.38.0/stan/lib/stan_math/lib/tbb/libtbb.12.dylib' (no such file), '/Library/Frameworks/R.framework/Resources/lib/libtbb.12.dylib' (no such file), '/Library/Java/JavaVirtualMachines/jdk-11.0.18+10/Contents/Home/lib/server/libtbb.12.dylib' (no such file), '/var/folders/rj/qpt02tfx4zlgjdyxvr878g1w0000gp/T/rstudio-fallback-library-path-660936210/libtbb.12.dylib' (no such file)
Please provide this additional information in addition to your question:
Hmm, that’s strange. You said you can run cmdstan from the terminal but not cmdstanr from RStudio. How about cmdstanr from the terminal? Can you try opening R in the terminal instead of RStudio and running the cmdstanr model you tried via cmdstanr (not just cmdstan)? Does that give you the same error? It would be helpful to know if this is isolated to RStudio or not.
(@WardBrian seems like another TBB issue, although this time on Mac)
You said you can run cmdstan from the terminal but not cmdstanr from RStudio.
Yes, that’s right.
How about cmdstanr from the terminal? Can you try opening R in the terminal instead of RStudio and running the cmdstanr model you tried via cmdstanr (not just cmdstan)?
I have the same error. (see image: Left is via R and cmdstan R, right is via terminal and cmdstan)
Either remove or cause the error mentioned before. But I guess that this line is only 'executed’ when running directly from the terminal for some reason.
Edit 2: If I run the following code in R, then it’s working:
Given that our CI is passing on macOs-26 (Tahoe) and you’re now seeing the same issue from the terminal outside of RStudio, I would say that this isn’t a general cmdstanr/Tahoe bug. From what you posted I think because you’re setting a large DYLD_LIBRARY_PATH that includes Homebrew’s TBB that must be affecting which TBB libraries CmdStan picks up at runtime. (@WardBrian would know better than I do if that assessment is correct, but that seems likely to me.)
I’m not sure if this would work, but you could also try to reinstall cmdstan from a clean R session with DYLD_LIBRARY_PATHunset, e.g.
That might fix the underlying problem so that you don’t need to add anything to your .Rprofile file. But it’s also possible that if your .bash_profile stays the same you might still pick up the wrong TBB, I don’t know.
As a fallback you can use the workaround that you found and add it to .Rprofile.
I agree with @jonah’s assessment. Having another copy of TBB in your environment is fine on macOS, but you either need to have it every time (meaning when you install, and when you build the model, and when you sample the model) or you should avoid having it at all these points in time
If you did want cmdstan to use the home brew version, there is some make/local logic you can set that would avoid needing to fiddle with DL_LIBRARY_PATH
or you should avoid having it at all these points in time
This seems fair. I think it was set-up by some application i no longuer used. I cleanup my bash_profile to avoid all those inclusuon to DYLD_LIBRARY_PATH:
[edelaire1@home-imglab01:~/.cmdstan/cmdstan-2.38.0/examples/bernoulli]$ ./bernoulli sample data file=bernoulli.data.json
dyld[32505]: Library not loaded: @rpath/libtbb.12.dylib
Referenced from: <3C351C14-BB2C-3AF8-9B38-3C67822792FE> /Users/edelaire1/.cmdstan/cmdstan-2.38.0/examples/bernoulli/bernoulli
Reason: tried: '/Applications/freesurfer/8.0.0/lib/gcc/lib/libtbb.12.dylib' (no such file), '/Users/edelaire1/.cmdstan/cmdstan-2.38.0/stan/lib/stan_math/lib/tbb/libtbb.12.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/edelaire1/.cmdstan/cmdstan-2.38.0/stan/lib/stan_math/lib/tbb/libtbb.12.dylib' (no such file), '/Users/edelaire1/.cmdstan/cmdstan-2.38.0/stan/lib/stan_math/lib/tbb/libtbb.12.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/edelaire1/.cmdstan/cmdstan-2.38.0/stan/lib/stan_math/lib/tbb/libtbb.12.dylib' (no such file)
I guess, I still need to let cmdstan know where is the tbb version included in cmdstan ?
After that, I could sample from the model in R and from the terminal. But i guess that’s not really the solution as it’s need to be executed after compiling every model.
Before that, it asked me to run : otool -L examples/bernoulli/bernoulli which return :
home-imglab01:cmdstan-2.38.0 edelaire1$ otool -L examples/bernoulli/bernoulli
examples/bernoulli/bernoulli:
@rpath/libtbb.12.dylib (compatibility version 12.0.0, current version 12.12.0)
@rpath/libtbb.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libtbbmalloc.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libtbbmalloc_proxy.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 2000.67.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1356.0.0)
Note: to make it less confusing, i removed everything i had in .bash_profile and .bashrc so we know there is no variable set.
Finally, ChatGPT told me to add this to the local makefile:
R is fussy so I just use cmdstan and then upload the samples to R, and then use R stan. it’s too cumbersome. But I don’t mind working with command line, I prefer it. I’m using WSL and it’s like a VM for ubuntu on windows, but may switch back to Ubuntu. But managing R packages, apparently, is always tricky. I haven’t done any R packages. Stan is cool, but you get a lot of stuff developed by a grad student that doesn’t work. For linear modeling it’s cool, but for the niche stuff, meh. It’s also a slow programming language.
That’s probably fins, the rpath should be being set by our makefiles but something in your environment must still be overloading it.
The “official” way to use a custom TBB is to set TBB_LIB to the desired location, which should be more or less equivalent to what you have done. If it works, I would probably just leave it