System command 'make' failed. Models won't compile

Hey all,

I can’t seem to compile any models whether I’m using cmdstanr, rstan, or brms. I’m getting similar errors for cmdstanr and brms (when cmdstanr is set as the backend), so I’ll focus on those…

Here’s the code I’m running for cmdstanr:

unlocked_folder <- "path_to_whitelisted_folder_on_my_work_computer"

## data for test model
data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
## model code for cmdstanr
mod_string <- "
data {
   int<lower=0> N;
   int<lower=0,upper=1> y[N];
 }
 parameters {  
   real<lower=0,upper=1> p;
 }
 model {
   p ~ beta(1,1);  // uniform prior on interval 0,1
   y ~ bernoulli(p);
}
"

file <- write_stan_file(mod_string, dir= unlocked_folder )

mod <- cmdstan_model(file)

The result is…

Compiling Stan program...
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/<my_username>/OneDrive: Is a directory.  Stop.
---
Type .Last.error to see the more details.
> .Last.error
<system_command_status_error/rlib_error_3_0/rlib_error/error>
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/<my_username>/OneDrive: Is a directory.  Stop.
---
Backtrace:
1. cmdstanr::cmdstan_model(file)
2. CmdStanModel$new(stan_file = stan_file, exe_file = exe_file, …
3. local initialize(...)
4. self$compile(...)
5. cmdstanr:::get_cmdstan_flags("STANCFLAGS")
6. cmdstanr:::wsl_compatible_run(command = "make", args = c(paste0("print-", …
7. base::do.call(processx::run, run_args)
8. (function (command = NULL, args = character(), error_on_status = TRUE, …
9. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, …

And here’s a similar error I get when trying to fit the same model with brms using cmdstanr as a backend. First the code…

options(cmdstanr_write_stan_file_dir = unlocked_folder)

brms_fit <- brm(y ~ 1, family="bernoulli", 
           data=data.frame(y = data_list$y), backend="cmdstanr")

And here’s the error:

Compiling Stan program...
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/<my_username>/OneDrive: Is a directory.  Stop.
---
Type .Last.error to see the more details.
> .Last.error
<system_command_status_error/rlib_error_3_0/rlib_error/error>
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/<my_username>/OneDrive: Is a directory.  Stop.
---
Backtrace:
 1. brms::brm(y ~ 1, family = "bernoulli", data = data.frame(y = data_list$y), …
 2. brms::do_call(compile_model, compile_args)
 3. brms:::eval2(call, envir = args, enclos = envir)
 4. base::eval(expr, envir, ...)
 5. base::eval(expr, envir, ...)
 6. local .fun(model = .x1, backend = .x2, threads = .x3, opencl = .x4, …
 7. local .compile_model(model, ...)
 8. brms:::eval_silent(do_call(cmdstanr::cmdstan_model, args), type = "message", …
 9. base::eval(expr, envir)
10. base::eval(expr, envir)
11. brms::do_call(cmdstanr::cmdstan_model, args)
12. brms:::eval2(call, envir = args, enclos = envir)
13. base::eval(expr, envir, ...)
14. base::eval(expr, envir, ...)
15. local .fun(stan_file = .x1)
16. CmdStanModel$new(stan_file = stan_file, exe_file = exe_file, …
17. local initialize(...)
18. self$compile(...)
19. cmdstanr:::get_cmdstan_flags("STANCFLAGS")
20. cmdstanr:::wsl_compatible_run(command = "make", args = c(paste0("print-", …
21. base::do.call(processx::run, run_args)
22. (function (command = NULL, args = character(), error_on_status = TRUE, …
23. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, …

I tried rebuild_cmdstan() but it didn’t help.

I’d be grateful for any ideas from anyone about how to fix this.

Thank you.

A couple of things to check:

  • When you ran rebuild_cmdstan() did it all complete successfully?

  • Does the same error occur if you pause your OneDrive sync?

  • Does the same error occur for the example model: cmdstanr::cmdstanr_example(example = "logistic", method = "sample")

Hey @andrjohns I appreciate the response and ideas. It looks like rebuild_cmdstan() does not complete successfully. Here’s the error:

mingw32-make: *** Waiting for unfinished jobs....
mingw32-make: *** [stan/lib/stan_math/make/libraries:64: stan/lib/stan_math/lib/sundials_6.1.1/src/nvector/serial/nvector_serial.o] Error 1

I tried pausing OneDrive and retrying everything, and running the example models, and got the same errors.

For what it’s worth, check_cmdstan_toolchain(fix = TRUE) outputs The C++ toolchain required for CmdStan is setup properly!

I really appreciate your help. Thank you.

Okay. I got fixated on the “OneDrive” thing because none of the files I’m running are located in OneDrive. I tried fully changing the location of OneDrive and rerunning the script and the above errors are now gone. No idea why or if it was instead fixed by some intermediate step that I don’t remember taking.

However, the model now fails with:

Compiling Stan program...
mingw32-make: *** [make/program:58: C:\SOMApps\temp_model_files\RtmpM9uTaR\model-3ef47423ed.exe] Error 1

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

Relevant discourse threads I can find with this error seem to end with the Windows user giving up on Stan, which I don’t want to do.

Is the problem potentially caused by cmdstanr trying to use a 32-bit compiler when my machine is 64-bit?

rebuild_cmdstan() still fails with

mingw32-make: *** [stan/lib/stan_math/make/libraries:64: stan/lib/stan_math/lib/sundials_6.1.1/src/nvector/serial/nvector_serial.o] Error 1
mingw32-make: *** Waiting for unfinished jobs....
mingw32-make: *** [stan/lib/stan_math/make/libraries:64: stan/lib/stan_math/lib/sundials_6.1.1/src/sundials/sundials_math.o] Error 1

After a fresh install of Rstan I can fit models! Sorry, this was a messy post and I can’t say I understand what was going on with my computer.

Hi andrjohns, I had the same problem with peopletress but didn’t get the luck to have it fixed. Please find my error message:

> cmdstanr::cmdstanr_example(example = "logistic", method = "sample")
Compiling Stan program...
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/{myusername}/OneDrive: Is a directory.  Stop.
---
Type .Last.error to see the more details.
> .Last.error
<system_command_status_error/rlib_error_3_0/rlib_error/error>
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/MYUSERNAME/OneDrive: Is a directory.  Stop.
---
Backtrace:
 1. cmdstanr::cmdstanr_example(example = "logistic", method = "sample")
 2. cmdstanr::cmdstan_model(tmp)
 3. CmdStanModel$new(stan_file = stan_file, exe_file = exe_file, …
 4. local initialize(...)
 5. self$compile(...)
 6. cmdstanr:::get_cmdstan_flags("STANCFLAGS")
 7. cmdstanr:::wsl_compatible_run(command = "make", args = c(paste0("print-", …
 8. base::do.call(processx::run, run_args)
 9. (function (command = NULL, args = character(), error_on_status = TRUE, …
10. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, …
>

I have followed this page: Getting started with CmdStanR • cmdstanr (mc-stan.org) and I could compile the bernoulli.stan example file successfully. However, when I used my own stan file, it gave me the above error message even if I moved my stan file to the bernoulli.stan’s folder. Why would that happen? Thanks!

What is the output you get from:

cmdstanr::cmdstan_path()

Thanks for your quick response! The output is
"C:/CmdStan/cmdstan-2.32.2"

Are you able to successfully run:

cmdstanr::rebuild_cmdstan()
cmdstanr::cmdstanr_example("schools_ncp", "sample", quiet = FALSE)

I just ran the code you provided. For the first line cmdstanr::rebuild_cmdstan(), what indicates that it was successfully run? I saw many words, some of which are in red fonts, and at the end it says cmdstan 2.32.1 was built. I did notice that it asked me to add tbb to the environment variable PATH, which I did. What about the suggestion of mingw32-make install-tbb? Is that required or recommended? For the second line cmdstanr::cmdstanr_example("schools_ncp", "sample", quiet = FALSE), I got the same error as before.

What’s your output from running:

.libPaths()

C:/Users/{myusername}/AppData/Local/Programs/R/R-4.3.0/library

At this point the main thing that’s confusing me is why there is an error related to your OneDrive folder when you’re running the example models:

make: *** /c/Users/MYUSERNAME/OneDrive: Is a directory.  Stop.

From the steps above, neither cmdstan nor your R packages (namely cmdstanr) are installed in your OneDrive, so there’s no reason for it to be included.

For some more debugging info, can you post the output from running the following:

library(cmdstanr)
bernfile <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
bernmod <- cmdstan_model(bernfile, quiet = FALSE, force_recompile = TRUE)

logisticfile <- system.file("logistic.stan", package = "cmdstanr")
logisticmod <- cmdstan_model(logisticfile, quiet = FALSE, force_recompile = TRUE)

Unfortunately, both of them gave me the original error message… I

Can you post the full outputs from both commands?

And also, what output do you get from: getwd()?

Hi andrjohns, please find the full output from your suggested commands. Also, I tried getwd() and found it was on a directory under my onedrive, which contains spaces. Therefore, I setwd() to my local directory and reinstalled cmdstanr, cmdstan and rstan, but still got the following error messages.

> library(cmdstanr)
> bernfile <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.st$
> bernmod <- cmdstan_model(bernfile, quiet = FALSE, force_recompile = TRUE)
Compiling Stan program...
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/{myusername}/OneDrive: Is a directory.  Stop.
---
Type .Last.error to see the more details.
> .Last.error
<system_command_status_error/rlib_error_3_0/rlib_error/error>
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/{myusername}/OneDrive: Is a directory.  Stop.
---
Backtrace:
1. cmdstanr::cmdstan_model(bernfile, quiet = FALSE, force_recompile = TRUE)
2. CmdStanModel$new(stan_file = stan_file, exe_file = exe_file, …
3. local initialize(...)
4. self$compile(...)
5. cmdstanr:::get_cmdstan_flags("STANCFLAGS")
6. cmdstanr:::wsl_compatible_run(command = "make", args = c(paste0("print-", …
7. base::do.call(processx::run, run_args)
8. (function (command = NULL, args = character(), error_on_status = TRUE, …
9. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, …
> logisticfile <- system.file("logistic.stan", package = "cmdstanr")
> logisticmod <- cmdstan_model(logisticfile, quiet = FALSE, force_recompile = $
Compiling Stan program...
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/{myusername}/OneDrive: Is a directory.  Stop.
---
Type .Last.error to see the more details.
> .Last.error
<system_command_status_error/rlib_error_3_0/rlib_error/error>
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/{myusername}/OneDrive: Is a directory.  Stop.
---
Backtrace:
1. cmdstanr::cmdstan_model(logisticfile, quiet = FALSE, force_recompile = TRUE)
2. CmdStanModel$new(stan_file = stan_file, exe_file = exe_file, …
3. local initialize(...)
4. self$compile(...)
5. cmdstanr:::get_cmdstan_flags("STANCFLAGS")
6. cmdstanr:::wsl_compatible_run(command = "make", args = c(paste0("print-", …
7. base::do.call(processx::run, run_args)
8. (function (command = NULL, args = character(), error_on_status = TRUE, …
9. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, …
>

Ok, I think I figured out what happened. There was a folder named “OneDrive” under the directory “/c/Users/{myusername}”, which is different from my formal OneDrive folder. I deleted it, so it works. Thanks!

1 Like

I had a similar error when trying to run rethinking::ulam() or cmdstanr::cmdstan_model():

I would get:

Compiling Stan program...
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/first-last/OneDrive: Is a directory.  Stop.
Type .Last.error to see the more details.

Like you, I was able to fix the issue by deleting one of two folders that started with “OneDrive”
C:\Users\first-last\OneDrive Deleted (It was empty)
C:\Users\first-last\OneDrive - MMC Kept (had OneDrive files in it)

However, I cannot figure out why the Stan program wanted to look in that path. My working directory, R libraries, and cmdstanr installation were set elsewhere, like C:\cmdstanr\cmdstan-2.32.2.

I’m not sure, it’s definitely strange. Unfortunately I’ve been seeing this issue with OneDrive folders more often recently (a few times on the forum but also working with some collaborators who use Windows). At least it’s fixable by deleting it, but ideally that wouldn’t be necessary.

Hello, I’m new to Stan and trying to get the program running. I seem to be having the same issues as users here, but haven’t been able to solve the problem.

library(cmdstanr)
bernfile <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
bernmod <- cmdstan_model(bernfile, quiet = FALSE, force_recompile = TRUE)

Compiling Stan program...
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
make: *** /c/Users/{usernamefolder}/OneDrive: Is a directory.  Stop.
---


> getwd()
[1] "C:/Users/{usernamefolder}/OneDrive - {agency}/Documents"

Any recommendations are welcome. Thank you