Error in rstan

OK. This is a pre-Stan problem (although there will be Stan problems once you get past this). Maybe @coatless recognizes this error with helloworld.cpp ?

Well thatā€™s good to know (I guess) ā€¦ I had RStan working 2 days ago until Catalina appeared. So the question is did the update do break that component or once something further down the track broke, did I break something upstream.

Catalina triggered the unknown exceptions problem, but that wouldnā€™t be relevant to that helloworld.cpp thing.

So I had some progress.

I applied this fix to Makevars

sudo touch ~/.R/Makevars && sudo echo 'CPPFLAGS="-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"' >> ~/.R/Makevars

and this now runs:

example(stan_model, run.dontrun = TRUE)

which is great ā€¦

but when I run something in brms

[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] "  c++ exception (unknown reason)"    

back where we were!
Itā€™s a game of inches I guess.

and helloworld.cpp works now crucially

OK. Weā€™ll post on the Dealing with Catalina thread once we figure out how to deal with the ā€œc++ exception (unknown reason)ā€.

Quick note:

This is required on R 3.6.0. R version 3.6.1 and higher does not need this statement.

That said, better flag instructions probably would be:

sudo mkdir -p ~/.R

# Fill with appropriate flag statements
sudo 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
# clang: end
EOF

Note the addition of CPPFLAGS.

1 Like

@bgoodri and @coatless, Iā€™ve sent some more info in the other thread, but I tested something else now. I removed .R/Makevars completely. Then I ran foo.R (1.5 KB).

If I remove Makevars it samples nicely. If I put it back it gives me:
c++ exception (unknown reason)
and if I remove Makevars again, it samples nicely againā€¦

My Makevars looks like this:

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

And if I put " around the ā€œ-isysroot ā€¦ sdkā€ it doesnā€™t work, and since itā€™s a directory I even tried putting / at the end.

But now I tried another example and it gave me the same errorā€¦

I use

system(ā€œclang++ --versionā€)
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /usr/local/clang7/bin

1 Like

thanks @coatless, Iā€™ve updated my flag instructions.

Thanks!!! This solved a similar problem on Mac M1 Monterey

For folks stumbling upon this issue, please note weā€™ve discontinued the macOS installer package that set up the toolchain in favor of an R package called {macrtools}. You can obtain it from:

Code:

# install.packages("remotes")
remotes::install_github("coatless-mac/macrtools")
macrtools::macos_rtools_install()

Walkthrough video:

Video: Installing and using the  package to setup the R Compilation Toolchain for macOS

For more details, please see:

https://mac.thecoatlessprofessor.com/macrtools