Dealing with Catalina III

As of January 1, 2020, the Catalina version of the Mac OSX operating system prevents the recommended C++ toolchain installer by @coatless from running. If you try, you will see something like


To get around this problem at the moment, you need to follow the instructions starting at “Manual Install Guide” at

https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/

If you have questions, follow up below. Then, you will probably need to do a

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

in a clean R session.

4 Likes

The RStan installation instructions here need to be updated.

It is currently possible on a mac with catalina to run install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE), have it not ask you to compile from source, and have pkgbuild::has_build_tools(debug = TRUE) return TRUE and still have rstan compilation problems.

I now know this because of a group of undergraduates chasing me with pitchforks.

Is the correct advice for all cases to do the manual install guide above and install from source?

Thanks!

Yes. Unfortunately, the pkgbuild::has_build_tools function tests whether it can compile a hello world program in C, which Catalina with Xcode can do. However, Catalina with Xcode miscompiles C++ so as to mispropagate exceptions under R, so most non-trivial Stan programs will terminate the MCMC without returning results. That is why we use LLVM clang++ rather than Xcode clang++ until Apple started blocking our toolchain installer starting January 1 because it is not a certified Apple Developer application.

If the people would put down their pitchforks and read the wiki, it does eventually say

If this line ultimately returns TRUE , then your C++ toolchain is properly installed and you can jump to the next section, unless you have the Catalina version of the Mac OSX operating system (see 3 below).

3 If you use a Mac, a link will appear but do not click on it. Instead go here

which takes you to a page that says

We recommend using the macOS R toolchain installer for pre-Catalina versions of the operating system. If you have Catalina, then you need to follow these instructions starting from “Manual Install Guide” to download and configure your C++ toolchain.

Suggestions are more than welcome as to how to reword that or anyone can just edit the wiki pages themselves. But I don’t know how better to explain in a few words why the only way forward at the moment is so messed up on Macs.

2 Likes

I might make a specific “If you have Catalina” section tomorrow.

1 Like

I installed rstan on Catalina today following all previous instructions. Everything works perfectly fine and straightforward if I simply ignore the extra Makevars component in the “Manual Install Guide”:

Note: If you are on macOS Mojave (10.14) or higher, you will need to add into ~/.R/Makevars a set of compilation flags.

mkdir -p ~/.R

# Fill with appropriate flag statements
cat <<- EOF > ~/.R/Makevars
# clang: start
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_CXXLDFLAGS+=-Wl,-rpath,\${R_HOME}/lib \${R_HOME}/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,\${R_HOME}/lib \${R_HOME}/lib/libc++abi.1.dylib
# clang: end
EOF

What does your makevars look like?

CXX14FLAGS=-O3 -march=native -mtune=native
CXX14FLAGS += -arch x86_64 -ftemplate-depth-256
And it works fine without those extra flags.

2 Likes

I’m trying to install Rstan on a new Mac with Catalina. I tried following the directions on Github, which were a departure from previous installations that specifically referenced Xtools.

I confess that after following multiple links from the above messages, opening the Terminal and trying to supply recommended commands … I’m not still not able to run a Stan model.

By chance, is there a step-by-step Catalina instruction guide in the works?

Catalina (mis)behaves different ways for different people. But the procedure is basically to install the toolchain by circumventing the security measures with a Ctrl-click to open it. And then see what, if anything, goes wrong. Sometimes it involves a

xcode-select --install

in the Terminal app or the Terminal tab of RStudio. Sometimes something else.

3 Likes