Rstan fails after computer crash (missing libc++abi.1.dylib)

My computer crashed in the middle of stan running using multiple cores in bash.

I installed the macos toolchain and followed the instructions here:

I also upgraded to R version 4.0.0 and reinstalled everything, following:

Although, still I can’t get rstan to be installed? When I run:

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

I get

clang-7: error: no such file or directory: '/Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib'
make: *** [] Error 1
ERROR: compilation failed for package ‘rstan’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan’
Warning in install.packages :
  installation of package ‘rstan’ had non-zero exit status

so it seems like the file is missing at the path. This is indeed the case:

mansmagnusson$ ls /Library/Frameworks/R.framework/Resources/lib/
libR.dylib		libRblas.dylib.dSYM	libgcc_s.1.dylib
libR.dylib.dSYM		libRlapack.dylib	libgfortran.5.dylib
libRblas.dylib		libRlapack.dylib.dSYM	libquadmath.0.dylib

Although I do not know where these files come from or how this could be fixed?

> writeLines(readLines(file.path(Sys.getenv("HOME"), ".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,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib
SHLIB_CXX11LDFLAGS+=-Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib
# clang: end
> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.4

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

[1] sv_SE.UTF-8/sv_SE.UTF-8/sv_SE.UTF-8/C/sv_SE.UTF-8/sv_SE.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
[1] compiler_4.0.0 tools_4.0.0    packrat_0.5.0 

Hi Måns,

I don’t have anything extra in the ~/.R/Makevars file except for:

FC = /usr/local/gfortran/bin/gfortran
FLIBS = -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm

and in ~/.Rprofile I have:

## Revert to 'sequential' setup of PSOCK cluster in RStudio Console on macOS and R 4.0.0
if (Sys.getenv("RSTUDIO") == "1" && !nzchar(Sys.getenv("RSTUDIO_TERM")) &&["sysname"] == "Darwin" && getRversion() == "4.0.0") {
  parallel:::setDefaultClusterOptions(setup_strategy = "sequential")

That’s it. I use the latest RStudio and R v4.0.0.

Hi! Thank you @torkar, this got me going. I now follow the instructions from @Stephen_Martin here:

Removing ~/.R/Makevars and ~/.Renviron solved my problems! Thanks!

1 Like

Yes, this changed with R v4.0.0. :)

It may be worth stating that Makevars can contain things, just not compiler paths. I have indeed repeatedly said ‘you can just remove Makevars and .Renviron’ (on osx), because you don’t strictly need them anymore on R 4.0. But — That will also remove any optimization flags, like -O3 -mtune=native -march=native and the like. So your model will run slower.

I should probably make a thread outlining exactly what needs and does not need to be present for systems on R 4.0.

In sum: Makevars does not need compiler definitions (e.g., where to find includes, where to find the compiler); it can contain compiler configuration options (like mtune, march, O[ptimization level]). It’s just that previous versions of R and rstan relied on Makevars and Renviron defining some paths, which conflict with the latest R. So deleting them is the easiest approach; but the next step would be to add back in some optimization options.

Would be good with such a post yes, where you post recommended flags etc.

1 Like

And I now see that you have already done that :)

1 Like