Can't build cmdstan on Windows 10

I can’t make build cmdstan v2.24.0 on Windows 10 with rtools40.

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

NOTE: Please add /c/Users/nbanho/Documents/cmdstan/stan/lib/stan_math/lib/tbb to your PATH variable.
You may call

mingw32-make install-tbb

to automatically update your user configuration.
--- CmdStan v2.24.0 built ---

I added the PATH variable manually in the Advanced Settings on Windows already. Executing mingw32-make install-tbb won’t work either in this respect.

$ mingw32-make install-tbb
INFO: Could not find files for the given pattern(s).
cmd.exe /C install-tbb.bat
Permanently setting the PATH user environment variable:
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.
Please close this shell and open a new shell.
This will make the changes to the PATH variable
become active.

Does anyone know what to make of this?

Hi,

if you edited the path manually, you do not need to run install-tbb.

Just try to run

mingw32-make examples/bernoulli/bernoulli.exe

and then run

./examples/bernoulli/bernoulli.exe sample data file=examples/bernoulli/bernoulli.data.json

to see if everything works for the example model.

1 Like

I guess this is not the expected output?

$ mingw32-make examples/bernoulli/bernoulli.exe
INFO: Could not find files for the given pattern(s).
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.7 -I stan/lib/stan_math/lib/boost_1.72.0 -I stan/lib/stan_math/lib/sundials_5.2.0/include  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS      -c -MT src/cmdstan/main.o -M -E -MG -MP -MF src/cmdstan/main.d src/cmdstan/main.cpp
INFO: Could not find files for the given pattern(s).

--- Translating Stan model to C++ code ---
bin/stanc.exe  --o=examples/bernoulli/bernoulli.hpp examples/bernoulli/bernoulli.stan

--- Compiling, linking C++ code ---
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.7 -I stan/lib/stan_math/lib/boost_1.72.0 -I stan/lib/stan_math/lib/sundials_5.2.0/include  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS      -c  -x c++ -o examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.7 -I stan/lib/stan_math/lib/boost_1.72.0 -I stan/lib/stan_math/lib/sundials_5.2.0/include  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS            -Wl,-L,"C:/Users/nbanho/Documents/cmdstan/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"C:/Users/nbanho/Documents/cmdstan/stan/lib/stan_math/lib/tbb"  examples/bernoulli/bernoulli.o src/cmdstan/main.o  -static-libgcc -static-libstdc++       stan/lib/stan_math/lib/sundials_5.2.0/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/sundials_5.2.0/lib/libsundials_cvodes.a stan/lib/stan_math/lib/sundials_5.2.0/lib/libsundials_idas.a stan/lib/stan_math/lib/sundials_5.2.0/lib/libsundials_kinsol.a  stan/lib/stan_math/lib/tbb/tbb.dll -o examples/bernoulli/bernoulli.exe
rm -f examples/bernoulli/bernoulli.o
Intel TBB is not in PATH.
Consider calling
mingw32-make install-tbb
to avoid copying Intel TBB library files.
'stan/lib/stan_math/lib/tbb/tbb.dll' -> 'examples/bernoulli/tbb.dll'

Ah but the rest looks all good:

$ ./examples/bernoulli/bernoulli.exe sample data file=examples/bernoulli/bernoulli.data.json
method = sample (Default)
  sample
    num_samples = 1000 (Default)
    num_warmup = 1000 (Default)
    save_warmup = 0 (Default)
    thin = 1 (Default)
    adapt
      engaged = 1 (Default)
      gamma = 0.050000000000000003 (Default)
      delta = 0.80000000000000004 (Default)
      kappa = 0.75 (Default)
      t0 = 10 (Default)
      init_buffer = 75 (Default)
      term_buffer = 50 (Default)
      window = 25 (Default)
    algorithm = hmc (Default)
      hmc
        engine = nuts (Default)
          nuts
            max_depth = 10 (Default)
        metric = diag_e (Default)
        metric_file =  (Default)
        stepsize = 1 (Default)
        stepsize_jitter = 0 (Default)
id = 0 (Default)
data
  file = examples/bernoulli/bernoulli.data.json
init = 2 (Default)
random
  seed = 4079134329 (Default)
output
  file = output.csv (Default)
  diagnostic_file =  (Default)
  refresh = 100 (Default)


Gradient evaluation took 1.7e-05 seconds
1000 transitions using 10 leapfrog steps per transition would take 0.17 seconds.
Adjust your expectations accordingly!


Iteration:    1 / 2000 [  0%]  (Warmup)
Iteration:  100 / 2000 [  5%]  (Warmup)
Iteration:  200 / 2000 [ 10%]  (Warmup)
Iteration:  300 / 2000 [ 15%]  (Warmup)
Iteration:  400 / 2000 [ 20%]  (Warmup)
Iteration:  500 / 2000 [ 25%]  (Warmup)
Iteration:  600 / 2000 [ 30%]  (Warmup)
Iteration:  700 / 2000 [ 35%]  (Warmup)
Iteration:  800 / 2000 [ 40%]  (Warmup)
Iteration:  900 / 2000 [ 45%]  (Warmup)
Iteration: 1000 / 2000 [ 50%]  (Warmup)
Iteration: 1001 / 2000 [ 50%]  (Sampling)
Iteration: 1100 / 2000 [ 55%]  (Sampling)
Iteration: 1200 / 2000 [ 60%]  (Sampling)
Iteration: 1300 / 2000 [ 65%]  (Sampling)
Iteration: 1400 / 2000 [ 70%]  (Sampling)
Iteration: 1500 / 2000 [ 75%]  (Sampling)
Iteration: 1600 / 2000 [ 80%]  (Sampling)
Iteration: 1700 / 2000 [ 85%]  (Sampling)
Iteration: 1800 / 2000 [ 90%]  (Sampling)
Iteration: 1900 / 2000 [ 95%]  (Sampling)
Iteration: 2000 / 2000 [100%]  (Sampling)

 Elapsed Time: 0.008 seconds (Warm-up)
               0.026 seconds (Sampling)
               0.034 seconds (Total)

So cmdstan is now working? Sorry I was confused by all the warnings…

It’s fine, but it will keep copying the .dll file to you models, which is a bit wasteful. But everything will work.

I am guessing the problem is what you wrote in the PATH variable.

The path should be:
C:/Users/nbanho/Documents/cmdstan/stan/lib/stan_math/lib/tbb

I am not sure why it’s formatted as

/c/Users/nbanho/Documents/cmdstan/stan/lib/stan_math/lib/tbb

Thanks for your help!

I wrote the path exactly as you said it should be.

Did you restart the shell upon editing PATH? Maybe thats why you are seeing that.

Yes, multiple times, even restarted the computer.

Does it have to do something with that I use mingw64 from Rtools instead of cmd.exe to do things?

Oh, that is why you are seeing the path formatted that way then. RTools shell does not pick applications from PATH on Windows, as it can be more isolated from the rest of your system.

If you want to use the Rtools shell you will have to, therefore, live with the DLL files being copied or
run the below before you use cmdstan (every session)

export PATH=C:\Users\nbanho\Documents\cmdstan\stan\lib\stan_math\lib\tbb:$PATH

Ah ok, thanks. Sorry for this maybe stupid question, but what is the issue of .dll files being copied?

I don’t know if it is related, but I wanted to use cmdstanr. I am having problems now as it says that the CmdStan path has not been set yet,

main <- cmdstan_model(negbinom_file)
Compiling Stan program...
Error: CmdStan path has not been set yet. See ?set_cmdstan_path.

although it has been and cmdstan_path is showing it:

cmdstan_path()
[1] "C:/Users/SpAdmin/Documents/.cmdstanr/cmdstan-2.24.0"
Warning message:
Can't find CmdStan makefile to detect version number. Path may not point to valid installation.

Not a stupid question!

Do you mean in a sense why do we need to copy it? If that is the question that is related to how Windows handles linking your program with a .dll file. On windows you have two options to do that: Either the .dll is in one of the folders listed in your PATH or is in the same folder as your executable. And if cmdstan cant find the .dll in your PATH, the it will just copy it beside your .exe file to solve this problem.

Regarding your cmdstanr error:
Just install cmdstan again. I think this was a failed installation.
So run install_cmdstan(overwrite = TRUE, cores = 4)

Thanks for this explanation. I meant more if copying the .dll file will affect my Stan experience later on (e.g., performance or memory issues, or something not running as per default)? Otherwise, I think I could live with it.

Perfect, running install_cmdstan() worked perfectly. Looking forward to the runtime improvements.

Thank you so much for taking the time to help, made my day! :)

1 Like

No, just a few MBs wasted :) But its 2020, so yeah, a few MBs isn’t a big deal I can imagine.

If you are going to use cmdstanr, even the copying won’t happen as cmdstanr handles the PATH stuff automatically.

Glad to hear that! Enjoy!

1 Like

I have big problems installing cmdstanr. When I run rebuild_cmdstan(),
it ends on


NOTE: Please add C:/Users/Polly/Documents/.cmdstan/cmdstan-2.33.1/stan/lib/stan_math/lib/tbb to your PATH variable.
You may call

mingw32-make install-tbb

but I have no idea how to do this and all my googling always leads me here. My hope is that this will fixes cmdstanr because currently it is not working.