Dealing with Catalina

But you are saying you got clang++ from homebrew rather than from @coatless installer or from ?

I’m pretty sure clang++ came from XCode. I don’t remember installing either the coatless software or the cran macosx tools you linked to.

BookTwo:bin $ which clang++
BookTwo:bin $ clang++ --version
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Applications/

My R installation definitely came from homebrew (using brew install r), which is what I was trying to say above.

OK. It is known to be possible to avoid the mishandled exceptions if you avoid all of R’s clang stuff, but that is not a general enough workaround for us (or Rcpp / inline). In principle, everyone could just use Xcode but you lose out on the ability to use OpenMP and all the R packages compiled on CRAN that have Stan programs are still broken.

From reading @nicokist’s output, he’s using the homebrew compiler…

So, moving totally away from R’s official binary works… Maybe this should be escalated over to Simon (macOS CRAN maintainer)

If I had a Mac, I would. But I am not much use when I have to borrow someone else’s machine (that has Catalina) to respond to posts with test cases.

I can say that

Rcpp::sourceCpp(code = 
#include <Rcpp.h>
using namespace Rcpp; 

// [[Rcpp::export]]
int throw_exception() { 
  std::stringstream errmsg; errmsg << "this is an exception";
  throw std::domain_error(errmsg.str()); 
  return 0;


works correctly (i.e. says “this is an exception”) if

  • One uses clang++ on Linux
  • One uses homebrew’s R on a Mac with Catalina
  • One uses Xcode’s clang++ on a Mac with Catalina, provided no other C++ packages from CRAN have previously been loaded

And the problem has not much to do with Stan, except that we call Rcpp::sourceCpp and inline::cxxfunction and throw exceptions at runtime. But even packages like rstanarm wiith Stan programs that are compiled in advance on CRAN are affected.

Any updates?

Still broken

If you are using Catalina with the recommended clang++ installer, try the advice in


Worked a treat - thank you! :)

Thank you for that! I have installed them a while ago, so I just ran the code you provided. However, after running it, my stan file could check its gramma once before it didn’t work again. Is there anything I’m not doing correctly? Thanks!

You may have to reinstall it from source at the moment with

install.packages("rstan", type = "source")

Does this mean we will have another break when R3.7 moves to clang 8?

Wouldn’t surprise me but my guess is that when clang8 is introduced, @coatless will update the Mac installer to use it and it will set SHLIB_CXXFLAGS to link against whatever libc++.1.dylib comes with R, which one would expect CRAN to have compiled with clang8.

I’m actually more worried about Windows for R 3.7.

Thanks so much!

Next version of R will be 4.0.0 to account for the compile toolchain switch, c.f.


Have you begun testing with RTools 4.0? Jeroen Ooms made it available:

Yes, I have been encouraging people to test rstan on it

for a while, but AFAIK I am the only one who has. It works (except LTO) for me, but it is a huge change.

I just tried this (after uninstalling RStan and using @coatless new installer) and got:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun ERROR: compilation failed for package ‘rstan’

So it appears that I am unable to actually compile Stan. Have you seen this error anywhere else since the Catalina roll out?

Try first doing xcode-select --install from the Terminal app or the Terminal tab of RStudio.

So, the installer attempts to install the Xcode CLI tools for you. In the process, we trigger:

sudo xcode-select --reset

And then

sudo xcode-select --install

The reset should fix the xcrun error, From there, the installation should be fine.

What macOS are you on? Mojave or Catalina?

I’m running Catalina (unfortunately). running xcode-select --install seems to have fixed the xcrun error (at least it did for installing cmdstanr which failed with a similar error initially). Unfortunately, I’m still waiting for that to finish compiling and haven’t been able to try install.packages(“rstan”, type = “source”) yet. As soon as cmdstanr is finished, I’ll give that a shot and post an update.