Compilation error on macOS Monterey; "error: no member named 'strtoul' in the global namespaceusing", "Error in sink(type = "output") : invalid connection"

Hello! I’m trying to replicate an example of fitting an autoregressive model in rstan (Autoregressive Modeling in Stan), and am running into compiler issues, which is weird, because everything was working as normal a few weeks ago, and I haven’t updated my OS or R/RStudio since then.

The example I’m trying to replicate is short, so I’ll paste it here:

# The model
data {
  int<lower=0> K;  // Order of Autoregression
  int<lower=0> N; // number of observations
  real y[N];      // Outcome
parameters {
  real alpha;
  real beta[K];
  real sigma;
model {
  for (n in (K+1):N) {
    real mu = alpha;
    for (k in 1:K)
      mu += beta[k] * y[n-k];
      y[n] ~ normal(mu, sigma);
", "AutoRegressive_Trial.stan")

# Compile model

# rstan_options(auto_write = TRUE)
model <- stan_model("AutoRegressive_Trial.stan")

I’ve commented out the rstan_options(auto_write = TRUE) line because I read in another post that doing so might fix the problem, but I’ve had no such luck.

Here’s the error I’m getting:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  /Applications/ error: no member named 'strtoul' in the global namespaceusing ::strtoul;      ~~^fatal error: too many errors emitted, stopping now [-ferror-limit=]20 errors generated.make: *** [filef63a2e5990f7.o] Error 1
Error in sink(type = "output") : invalid connection

I’ve read on other posts that this can be caused by an installation error, but I’m just not sure how to diagnose the problem here, so any help would be much appreciated :)

Thanks so much for any suggestions!

It looks like there are issues with your toolchain. If you use homebrew then try running brew doctor and seeing if any issues are reported, otherwise try reinstalling the xcode command line tools

Thank you! I’m not using home-brew, but I’ll re-install Xcode and update the post! :)

EDIT: Re-installing Xcode took forever but it worked!!

1 Like