Issue compiling Stan on R 4.0 / Catalina

Very new to Stan, recently updated to R 4.0 and Catalina (10.15.4), using RStudio 1.3.959.

Starting with @rcpedroso’s example from the dealing with R 4.0 thread:

 # Load rstan

# Set seed

# Make data
stan_data <- list(y = rnorm(500, 0, 1),
                  N = 500)

# Define model
stan_code <- "
  This model is just for testing.
functions {
    real times_two(real x) { // Custom function test.
data {
    int N; // Data length
    vector[N] y; // Data
transformed data {
    real a = 2.0; // Constant Test
parameters {
    real<lower = 0> sigma; // Constraint test; residual SD
    real mu; // Mean
transformed parameters {
    real mu_over_sigma = mu / sigma; // Transformed param test.
model {
    mu ~ normal(0, 1); // ~ syntax test.
    target += student_t_lpdf(sigma | 5, 0, 1); // Increment test.

    y ~ normal(mu, sigma); // Likelihood
generated quantities {
    real b = normal_rng(0, 1); // RNG test
    real c = times_two(a*b); // Custom Function test.

# Compile model
sm <- rstan::stan_model(model_code = stan_code)

Here’s the error I’m getting, which I also get when I try to run the code I’m trying to work with:

Error in dyn.load(libLFile) :
unable to load shared object ‘/var/folders/b0/gny_hdjx72b12pbflnfxfys80000gn/T//RtmpYLUfwq/’:
dlopen(/var/folders/b0/gny_hdjx72b12pbflnfxfys80000gn/T//RtmpYLUfwq/, 6): Symbol not found: __ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev
Referenced from: /var/folders/b0/gny_hdjx72b12pbflnfxfys80000gn/T//RtmpYLUfwq/
Expected in: flat namespace
in /var/folders/b0/gny_hdjx72b12pbflnfxfys80000gn/T//RtmpYLUfwq/
Error in sink(type = “output”) : invalid connection

Here’s what’s in Makevars:


CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk



All I have in my Renviron file is:

I’ve confirmed that I’m up to date on XCode/command line tools.

I’m sure there’s something really silly buried in here that I’m just not seeing, but having read through a bunch of these threads tried all of the recommendations I’ve seen for Mac users I’m really at a loss. I’m also not sure whether this is a dealing with R 4.0 issue or a dealing with Catalina issue, though I suspect the latter.

Any help would be fantastic!

I was helped a lot by this post:

Hope it helps you too! :)

1 Like

This, from that post:

Undo the configurations made by macos-rtools:

  • Open spotlight, and launch terminal.
  • cd ~
  • mv .Renviron .Renviron.bak (this renames .Renviron, so R does not use it)
  • cd .R
  • mv Makevars Makevars.bak (this renames Makevars)

Seems to have worked. Thanks so much! I figured it’d be something simple, likely simply starting over from scratch on Makevars.