# Dealing with Catalina II

**URL:** <https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802>\
**Category:** RStan\
**Tags:** rstan\
**Created:** [November 7, 2019, 11:48pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802 "2019-11-07T23:48:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [November 7, 2019, 11:48pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/1 "2019-11-07T23:48:44Z")

</div>

If you have Catalina and `clang++` installed from @coatless’s installer and rstan is not working, try the newest installer

> [@Dealing with Catalina II](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/48):
>
> Released a new version of the installer here: Special thanks to @bgoodri, @wds15, and @kevinushey for their efforts in helping identify problem and propose solutions.

from

> **[Releases · coatless-mac/r-macos-rtools](https://github.com/coatless-mac/r-macos-rtools/releases)**
>
> Scripts to build an \*\*unofficial\*\* Rtools-esq installer for the macOS R toolchain - coatless-mac/r-macos-rtools

---

<div class="post-metadata">

**Author:** ![Duncan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/duncan/32/4571_2.png) [@Duncan](https://discourse.mc-stan.org/u/Duncan)\
**Post date:** [November 8, 2019, 4:24am UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/2 "2019-11-08T04:24:08Z")

</div>

I tried this and got the error described here,  
[https://discourse.mc-stan.org/t/configuration-for-clang/4890](https://discourse.mc-stan.org/t/configuration-for-clang/4890)

when I tried to change the permissions (again), using  
`chmod g+rwx /Users/me/.R/Makevars`  
I received,  
`Unable to change file mode on /Users/me/.R/Makevars Operation not permitted`

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [November 8, 2019, 5:24am UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/3 "2019-11-08T05:24:17Z")

</div>

Maybe

```
sudo chmod g+rwx /Users/me/.R/Makevars

```

?

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [November 8, 2019, 7:11am UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/4 "2019-11-08T07:11:49Z")

</div>

Ben, I have @coatless’s installer and changed `Makevars` accordingly and then ran `rstan::stan_model` with [bar.stan](https://discourse.mc-stan.org/uploads/short-url/37DMp0E8RfynwSCLeYbCzQFYM2q.stan) (3.6 KB) .

```no-highlight
n=1000
x=-log(runif(n))
library(rstan)
fitted_model = stan_model(file='bar.stan')
stan_data <- list(y=x, N = n, ymin = 0)
stan_fit = sampling(fitted_model, data = stan_data)

```

Same thing happens:

> Chain 1: Iteration: 1 / 2000 [0%] (Warmup)  
> [1] “Error in sampler$call\_sampler(args\_list[[i]]) : "  
> [2] " c++ exception (unknown reason)”

Was this what you wanted?

My `Makevars` looks like this now:

```no-highlight
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 -I/usr/local/include
SHLIB_CXX14LD = /usr/local/clang7/bin/clang++ -L$(R_HOME)/lib/libc++.1.dylib

```

---

<div class="post-metadata">

**Author:** ![Duncan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/duncan/32/4571_2.png) [@Duncan](https://discourse.mc-stan.org/u/Duncan)\
**Post date:** [November 8, 2019, 12:03pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/6 "2019-11-08T12:03:22Z")

</div>

this ran fine after what you posted

`dat_list <- list(`  
` y = scale(mtcars$disp),`  
` b = scale(mtcars$cyl))`

`mtcars_model <- `  
` "`  
`data{`  
` vector[32] y;`  
` vector[32] b;`  
`}`  
`parameters{`  
` real beta;`  
` real alpha;`  
` real<lower=0> sigma;`  
`}`  
`model{`  
` vector[32] mu;`  
` sigma ~ exponential( 1 );`  
` alpha ~ normal( 0 , 1 );`  
` beta ~ normal( 0 , 1 );`  
` for ( i in 1:32 ) {`  
` mu[i] = alpha + beta * b[i];`  
` }`  
`y ~ normal( mu , sigma );`  
`}`

`" `

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [November 8, 2019, 1:19pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/7 "2019-11-08T13:19:57Z")

</div>

There should have been a

```
CXX14 = /usr/local/clang7/bin/clang++ -stdlib=libc++ -nostdinc++ -I/usr/local/clang7/include/c++/v1

```

in the ~/.R/Makevars somewhere.

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [November 8, 2019, 1:29pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/8 "2019-11-08T13:29:08Z")

</div>

Using the previous example I posted above, and my `Makevars` looking like this:

```no-highlight
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 -I/usr/local/include
SHLIB_CXX14LD = /usr/local/clang7/bin/clang++ -L$(R_HOME)/lib/libc++.1.dylib
CXX14 = /usr/local/clang7/bin/clang++ -stdlib=libc++ -nostdinc++ -I/usr/local/clang7/include/c++/v1

```

Leads to,

> Chain 4: Iteration: 1 / 2000 [0%] (Warmup)  
> [1] “Error in sampler$call\_sampler(args\_list[[i]]) : "  
> [2] " c++ exception (unknown reason)”

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [November 8, 2019, 2:24pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/9 "2019-11-08T14:24:18Z")

</div>

When you then do

```
dlls <- getLoadedDLLs()
paths <- vapply(dlls, `[[`, "path", FUN.VALUE = character(1))
invisible(lapply(paths, function(path) {
  
  if (!file.exists(path))
    return(FALSE)
  
  output <- system(paste("otool -L", shQuote(path), "| grep libc++ || true"),
                   intern = TRUE)
  if (length(output) == 0)
    return(FALSE)
  
  writeLines(paste0(path, ":"))
  writeLines(output)
  
}))

```

does it indicate that the .so files from the temporary directory are linked against  
/usr/lib/libc++.1.dylib ?

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [November 8, 2019, 2:29pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/10 "2019-11-08T14:29:59Z")

</div>

When I run your code after executing the example I get this (before executing the example it doesn’t output anything):

> /Users/rr/Library/R/3.6/library/Rcpp/libs/Rcpp.so:  
> /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)  
> /Users/rr/Library/R/3.6/library/scales/libs/scales.so:  
> /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)  
> /Users/rr/Library/R/3.6/library/tidyselect/libs/tidyselect.so:  
> /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)  
> /Users/rr/Library/R/3.6/library/dplyr/libs/dplyr.so:  
> /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)  
> /Users/rr/Library/R/3.6/library/rstan/libs/rstan.so:  
> /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)  
> /var/folders/5p/dlcj\_kd94bx83r83k\_d77j54pspdk5/T//RtmpyQ0YVv/file7bad2d33500f.so:  
> /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [November 8, 2019, 2:32pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/11 "2019-11-08T14:32:12Z")

</div>

> [@torkar](#):
>
> /var/folders/5p/dlcj\_kd94bx83r83k\_d77j54pspdk5/T//RtmpyQ0YVv/file7bad2d33500f.so:  
> /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)

OK. That is suppose to link against $(R\_HOME)/lib/libc++.1.dylib . We need to figure out why that is not happening despite the new ~/.R/Makevars . When you compile with `verbose = TRUE`, what are the lines that show how the compiler and linker are being called?

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [November 8, 2019, 2:34pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/12 "2019-11-08T14:34:53Z")

</div>

This?

> Compilation argument:  
> /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file7fda7e5f0e0b.cpp 2\> file7fda7e5f0e0b.cpp.err.txt  
> /usr/local/clang7/bin/clang++ -stdlib=libc++ -nostdinc++ -I/usr/local/clang7/include/c++/v1 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Users/torkarr/Library/R/3.6/library/Rcpp/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/unsupported" -I"/Users/torkarr/Library/R/3.6/library/BH/include" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/src/" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/" -I"/Users/torkarr/Library/R/3.6/library/rstan/include" -DEIGEN\_NO\_DEBUG -DBOOST\_DISABLE\_ASSERTS -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c file7fda7e5f0e0b.cpp -o file7fda7e5f0e0b.o  
> /usr/local/clang7/bin/clang++ -L/Library/Frameworks/R.framework/Resources/lib/libc++.1.dylib -dynamiclib -Wl,-headerpad\_max\_install\_names -undefined dynamic\_lookup -single\_module -multiply\_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o file7fda7e5f0e0b.so file7fda7e5f0e0b.o -L/Users/torkarr/Library/R/3.6/library/StanHeaders/lib/ -lStanHeaders -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [November 8, 2019, 2:35pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/13 "2019-11-08T14:35:32Z")

</div>

And the line below that?

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [November 8, 2019, 2:37pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/14 "2019-11-08T14:37:19Z")

</div>

updated above…

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [November 8, 2019, 2:40pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/15 "2019-11-08T14:40:24Z")

</div>

Wait Ben, my .Renviron is missing… I’ll update…

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [November 8, 2019, 2:44pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/16 "2019-11-08T14:44:48Z")

</div>

`.Renviron` in place, and running your function looks like this:

> /Users/torkarr/Library/R/3.6/library/Rcpp/libs/Rcpp.so:  
> /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)  
> /Users/torkarr/Library/R/3.6/library/scales/libs/scales.so:  
> /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)  
> /Users/torkarr/Library/R/3.6/library/tidyselect/libs/tidyselect.so:  
> /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)  
> /Users/torkarr/Library/R/3.6/library/dplyr/libs/dplyr.so:  
> /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)  
> /Users/torkarr/Library/R/3.6/library/rstan/libs/rstan.so:  
> /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)  
> /var/folders/5p/dlcj\_kd94bx83r83k\_d77j54pspdk5/T//Rtmp1dxXa1/file8434301b38ac.so:  
> /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)

And compiler output:

> Compilation argument:  
> /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file86f81f777c59.cpp 2\> file86f81f777c59.cpp.err.txt  
> /usr/local/clang7/bin/clang++ -stdlib=libc++ -nostdinc++ -I/usr/local/clang7/include/c++/v1 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Users/torkarr/Library/R/3.6/library/Rcpp/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/unsupported" -I"/Users/torkarr/Library/R/3.6/library/BH/include" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/src/" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/" -I"/Users/torkarr/Library/R/3.6/library/rstan/include" -DEIGEN\_NO\_DEBUG -DBOOST\_DISABLE\_ASSERTS -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c file86f81f777c59.cpp -o file86f81f777c59.o  
> /usr/local/clang7/bin/clang++ -L/Library/Frameworks/R.framework/Resources/lib/libc++.1.dylib -dynamiclib -Wl,-headerpad\_max\_install\_names -undefined dynamic\_lookup -single\_module -multiply\_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o file86f81f777c59.so file86f81f777c59.o -L/Users/torkarr/Library/R/3.6/library/StanHeaders/lib/ -lStanHeaders -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [November 8, 2019, 2:51pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/17 "2019-11-08T14:51:08Z")

</div>

What about just

```
Rcpp::sourceCpp(code = 
'
#include <Rcpp.h>

// [[Rcpp::export]]
int throw_exception() { 
  std::stringstream errmsg; errmsg << "this is the expected behavior";
  throw std::domain_error(errmsg.str()); 
  return 0;
}
'
)

throw_exception()

```

?

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [November 8, 2019, 2:52pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/18 "2019-11-08T14:52:23Z")

</div>

Restarted `RStudio` and ran your code:  
`Error in throw_exception() : this is the expected behavior`

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [November 8, 2019, 2:56pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/19 "2019-11-08T14:56:42Z")

</div>

OK. And you have StanHeaders and rstan from CRAN?

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [November 8, 2019, 2:57pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/20 "2019-11-08T14:57:41Z")

</div>

Sure. BUT, let me try it out again. What’s the best way to clean out `StanHeaders` and `rstan` completely?

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [November 8, 2019, 2:58pm UTC](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802/21 "2019-11-08T14:58:46Z")

</div>

```
remove.packages("rstan")
remove.packages("StanHeaders")
file.remove(".RData")

```

restart

```
install.packages("rstan", dependencies = TRUE)

```

[Next page](https://discourse.mc-stan.org/t/dealing-with-catalina-ii/11802.md?page=2)
