Cmdstan installation error

I am trying to install cmdstand to then use with cmdstanr but the installation fails whenever I try. I was following the install guide here:

Getting started with CmdStanR • cmdstanr (

I am using windows 11.

This is the error message:

> install_cmdstan(cores = 2)
The C++ toolchain required for CmdStan is setup properly!
trying URL ''
Content type 'application/json; charset=utf-8' length 14650 bytes (14 KB)
downloaded 14 KB

* Latest CmdStan release is v2.33.1
* Installing CmdStan v2.33.1 in C:/Users/conna/Documents/.cmdstan/cmdstan-2.33.1
* Downloading cmdstan-2.33.1.tar.gz from GitHub...
trying URL ''
Content type 'application/octet-stream' length 51051295 bytes (48.7 MB)
downloaded 48.7 MB

* Download complete
* Unpacking archive...
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file 'C:/Users/conna/Documents/.cmdstan/cmdstan-2.33.1/make/local': No such file or directory

Any advice would be appreciated!

It looks like there are some file read issues, let’s try manually downloading and untar-ing the cmdstan release, then call cmdstanr to build and install.

Can you try:

# Delete existing folder (if present)
unlink("C:/Users/conna/Documents/.cmdstan/cmdstan-2.33.1", recursive = TRUE)

download.file(url = "",
              destfile = "C:/Users/conna/.cmdstan/cmdstan-2.33.1.tar.gz")

  exdir = "C:/Users/conna/.cmdstan/cmdstan-2.33.1",
  extras = "--strip-components 1"

cmdstanr::rebuild_cmdstan(cores = 2)

So that didn’t work either. But It did let me know something was seriously up. This is a clean windows install but somehow my documents directory had become read only…

Fixed the permissions and all good. Thanks!

Yep, that’ll do it! Glad to hear it all worked out

1 Like

So I did a clean install, and everything seemed to work fine. But now I get the following error when compiling a model with the cmdstanr backend and opencl.

Can’t find an example of a similar error anywhere else.

: cannot find -lOpenCL: No such file or directory

collect2.exe: error: ld returned 1 exit status

mingw32-make: *** [make/program:59: C:\Users\conna\AppData\Local\Temp\RtmpoFS74o\model-39a83157ae8.exe] Error 1

Have you completed the setup steps for OpenCL from the manual: 18 Parallelization | CmdStan User’s Guide

Yep! No issues arose there.

I’m testing it with this relatively simple model in brms:

testmod <- brm(belief ~ rebel_troll + rebel_act + rebel_all + choice_norms + indiv_collectivism,
                  data = dat1,
                  family = cumulative(link ="probit"), 
                  iter = 4000,
                  warmup = 1000, 
                  chains = 3,
                  cores = 2,
                  opencl = opencl(c(0, 0)),
                  seed = 2023, 
                  backend = "cmdstanr")

The model works when specified without opencl

What was the output that you got from the clinfo command?

It has all the info for my AMD GPU, including the OpenCl version 2.0, if that is relevant.

That is the only device listed as my cpu (also AMD) doesn’t have official opencl support

Looks like you’ll need to update your compilation flags to correctly find the installed library. Can you run:

cpp_options <- list(
    "LDLIBS_OPENCL" = "-L'C:/Program Files (x86)/OCL_SDK_Light/lib/x86_64' -lOpenCl"
cmdstan_make_local(cpp_options = cpp_options,append = TRUE)

And then try the model again?


Also as an FYI we’ll add a setup/config step to cmdstanr (GH issue) to automatically handle OpenCL setup in the future, so make sure to let me know if there have been any other steps that you’ve had to complete that weren’t in the manual

Oh cool, that will be useful I imagine. I didn’t need to do any other steps than mentioned here. The first issue In the thread was was obviously a file permissions bug on my end, and the second one was solved with your above fix (updating compilation flags).

In the end the model using opencl is actually quite a bit slower :'), but this is probably just a function of the test models I am running.