Then I can compile the exception example and get the desired output. The key line above is the SHLIB_CXXLDFLAGS. The rpath instructs the linker to hard-code the path to the libraries found in the directory of R. Next I am hard-coding the path of the libc++abi.1.dylib as used by R. Doing so seems to resolve the problems.
So the above should fix our problems. I just reinstalled Rcpp, inline and RcppParallel as binary packages from CRAN. Then I installed rstan and the mvn_orange example does now sample just fine.
Can others please verify?
I think this resolves the issue - I have in the meantime started a thread on the Mac-SIG mailinglist which does not include the latest info here. A ABI compiler change is a really nasty thing… in particular as Apple apparently did not change the library names. So this is probably a bug in Apple’s shipped clang from my perspective (rather than a feature).
I’ve verified that both the solution given by @bgoodri and @wds15’s addition of SHLIB_CXXLDFLAGS works. I think @wds15’s approach is probably better as it: 1. relies less on specifying defaults for each language specification (c++{98, 11, 14,17}) and 2. uses R’s shipped ABI.
I don’t know enough about Macs to object. I guess it should have some $(R_HOME) stuff rather than /Library/Frameworks/R.framework/Resources/
I do wonder, however, what the implications for a src/Makevars file in a package like rstanarm or RBesT that comes with Stan programs that are compiled on CRAN. Should the src/Makevars file also have -Wl,-rpath,$(R_HOME)/lib $(R_HOME)/lib/libc++abi.1.dylib somewhere in it? What if the user has installed R someplace else?
First of all, thanks for all the hard work you put into this. I read through the other Catalina thread and this one, and although I think I followed all the steps, I somehow still get errors when running a Stan model through rstan (one that ran without errors in the previous version of Mac OS). These are the steps I took:
“upgrade” to Catalina (unfortunately). I’m now on Mac OS 10.15.1 (19B88)
remove rstan and StanHeaders (through clicking the ‘X’ in the RStudio packages pane)
in terminal: xcode-select --install
install the @coatless r-macos-rtools from the post above. My Makevars file is now as follows:
SHLIB_CXXLDFLAGS+=-Wl,-rpath,${R_HOME}/lib ${R_HOME}/lib/libc++abi.1.dylib # clang: end
confirm that the following works:
library(readr) # or another package with compiled C++
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;
}
'
)
throw_exception()
(i.e. output is Error in throw_exception() : this is an exception )
6. install.packages("rstan", type = "source", dependencies = TRUE)
7. run a model through rstan. Error messages:
[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] " c++ exception (unknown reason)"
Somehow 2 out of the 4 chains run fine while the other 2 give this error.
Can someone please help me out? I hope that I simply missed a crucial step in one of the threads. If not, please let me know what I can do to provide more information.
Thanks for the quick reply. After updating Makevars (I added these lines without touching the rest) I get the exact same behavior - 2 chains run fine, 2 chains crash immediately with the error message from before.
Cellar bin clang6 clang8 f-secure include man remotedesktop texlive
Homebrew clang4 clang7 etc gfortran lib opt share var
See anything wrong?
Interestingly, I restarted R and removed the saved Stan model (.rds file) again. This time when running it tells me Building R package from source requires installation of additional build tools. Do you want ot install the additional tools now?
Since I had removed the .rds files before posting here, this change must have come from updating the Makevars file with @bgoodri 's post. Any ideas what I’m missing now? xcode-select --install tells me the command line tools are already installed.
Apparently I was a bit sloppy. When removing the flags from @bgoodri’s post from Makevars, I still have R ask me to install additional build tools as soon as I start compiling a Stan model. Not sure why this happens, as it didn’t happen before.
Not a screenshot but hopefully this works for you:
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type ‘license()’ or ‘licence()’ for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type ‘contributors()’ for more information and
‘citation()’ on how to cite R or R packages in publications.
Type ‘demo()’ for some demos, ‘help()’ for on-line help, or
‘help.start()’ for an HTML browser interface to help.
Type ‘q()’ to quit R.
This is the output:
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.1
I did some Googling and was able to find what was wrong with my setup. Then I restarted my computer and reran the model from before and all chains are sampling now. Thanks @bgoodri, @coatless and @wds15 for your help with this!