Issue installing cmdstan

I’m trying to help my student install cmdstan through cmdstanr (on Windows) but keep getting the same error:

library(cmdstanr)

check_cmdstan_toolchain()
#> The C++ toolchain required for CmdStan is setup properly!

install_cmdstan(cores = 2, overwrite = TRUE) # install CmdStan

Last couple of lines of output:

  105 | #define TBB_VERSION_STRINGS TBB_VERSION_STRINGS_P(TBB)
      |                             ^~~~~~~~~~~~~~~~~~~~~
../tbb_2020.3/src/tbb/tbb_misc.cpp:202:42: note: in expansion of macro 'TBB_VERSION_STRINGS'
  202 | static const char VersionString[] = "\0" TBB_VERSION_STRINGS;
      |                                          ^~~~~~~~~~~~~~~~~~~
make[1]: Leaving directory '/c/Users/yahli/.cmdstan/cmdstan-2.38.0/stan/lib/stan_math/lib/tbb'
make[1]: *** [../tbb_2020.3/build/common_rules.inc:80: tbb_misc.o] Error 1
make: *** [stan/lib/stan_math/make/libraries:179: stan/lib/stan_math/lib/tbb/tbb.def] Error 2
make: *** Waiting for unfinished jobs....

Warning message:
There was a problem during installation. See the error message(s) above. 
fit_logit <- cmdstanr_example("logistic", force_recompile = TRUE, quiet = FALSE)
Compiling Stan program...
INFO: Could not find files for the given pattern(s).

INFO: Could not find files for the given pattern(s).

C
:\rtools45\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -ltbb: No such file or directory
C:\rtools45\x8
6_64-w64-mingw32.static.posix\bin/ld.exe: cannot find stan/lib/stan_math/lib/tbb/tbb.dll: No such file or directory

collect2.exe: error: ld returned 1 exit status

make: *** [make/program:82: C:/Users/yahli/AppData/Local/Temp/RtmpItUWJj/model-670470cb6958.exe] Error 1

Error: An error occured during compilation! See the message above for more information.

Any help is appreciated!

I don’t know much about Windows TBB issues, so hopefully @WardBrian or someone else can chime in here. But I think some of the important output may come earlier in the installation output, not just the last few lines. Earlier in the output were there any TBB related error messages?

Also, one important question:

Is the cmdstanr installation from the “release” on r-universe (e.g. installed via install.packages(“cmdstanr”, repos = c(‘``https://stan-dev.r-universe.dev``’, getOption(“repos”)))) or was it installed from Github (e.g. via remotes::install_github or pak::pak)? If it was installed from GitHub, how recently was it installed? We very recently (~5 days ago) merged a pull request that affects how the toolchain is handled on Windows, so it would be good to know how cmdstanr was installed and when.

It was installed from r-universe (but so did other students, who didn’t have this issue- should she try with pak?

As far as I could tell there were no errors regarding TBB during installation, but I’ll try and get the full installation output.

I think I had an issue with this. Go for command-line installations of the dependencies and make sure the versions are correct. Stan Math Library: Stan Math Library Docs are the proper packages, and then you can use, on ubuntu, sudo apt install blah blah, or I was using WSL (windows subsystem for linux) and I think you can use the same commands, I don’t remember. If you’re on windows, WSL is like a separate VM, that operates like ubuntu. I think it also uses apt. So I would make sure the stan/math dependencies are there first and then try re-installing. Also make sure you have the rtools tool chains installed, stuff like that.

They could try installing from GitHub and then restart R before trying to install_cmdstan again. I doubt that would fix it, but it shouldn’t hurt so maybe worth a shot.

Do you know if this is a personal computer or if it’s a managed university/work machine? If the former, it’s possible that just removing and reinstalling RTools could fix this. If the latter, it could be maybe be some policy/security restriction, but it’s hard to say just from that output.

I’m not a computer guy and have little confidence in my ability to do all of this on a student’s computer without causing damage :/

I’ll have her try pak.

It is a personal computer. She’s already removed and reinstalled RTools.

This is the full captured output from:

capture.output({
    library(cmdstanr)

    check_cmdstan_toolchain()

    install_cmdstan(cores = 2, overwrite = TRUE) # install CmdStan

    fit_logit <- cmdstanr_example("logistic", force_recompile = TRUE, quiet = FALSE)
  },
  file = "log.txt")

log.txt (444.6 KB)

So I was running cmdstan on WSL, it operates like ubuntu, and then pulling the data onto the windows “partition” to analyze it.

I just went through this… I forget exactly what I did. Use WSL, and then do something like this:

https://askubuntu.com/questions/1170054/install-newest-tbb-thread-building-blocks-on-ubuntu-18-04.

And then there may be dependencies you have to add. Check out I think I had to add some additional repos for the package manager, and then there was additional tool chains that I had to install in order to get TBB to run with cmdstan properly. There’s a way to add another repo that aren’t on the stock apt package manager repos. I saved some references, but they’re not comprehensive.

And you may have to follow the paper trail, and add some additional toolchains, to get cmdstan to cooperate with WSL.

I would just keep looking up stuff on stackoverflow and technical documentation and keep installing stuff… if it says cannot find xxx go ahead and look it up install instructions on stack overflow.

WSL operates like ubuntu, it’s kinda like a virtual machine. Good luck. This took me a few days.

Thanks for the full log. It appears there is an issue with the TBB build. Could you go to their cmdstan folder and get the contents of CMDSTAN/stan/lib/stan_math/lib/tbb/version_string.ver?

My hunch is that the first couple lines of this file will be missing a " (or possibly have too many), but I haven’t previously encountered this

2 Likes