Dealing with Catalina II

StanHeaders version ‘2.21.0.1’

Does it work if you call in R

Sys.unsetenv("PKG_CXXFLAGS")

after calling library(rstan) but before calling sourceCpp?

2 Likes

Yes, that fixes it!

OK. I guess just go that way for now. We had to set that environmental variable to move StanHeaders forward on CRAN but can remove it in the future.

Good to know, many thanks

Hi Everyone!

I used the latest installer linked above, but that left me with a non-working setup for running stan models. The reasons seems to be that the tools leave you with a ~/.R/Makevars with this content:

# 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
# clang: end

but for Stan we have to also modify the C++14 flags like this:

# 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

CXX14FLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPF14LAGS=-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

With the above changes for C++14 everything works now for me.

Tagging @mcol

… and for everyone who is blocked by Catalina not being allowed to install the .pkg file… a simple CTRL+right click on the file, then clicking “Open” will get the installer going (for me).

Did you want to tag somebody else? I’m not on Mac.

1 Like

ups… sorry… I meant @coatless

Thanks @torkar , this worked for me!

1 Like

works! Thanks so much!

1 Like

I had the same problem on macOS 10.15.4, and the solution worked perfectly. Many thanks!

@riko, note however that with R v4.0.0 nothing much is needed in the ~/.R/Makevars anymore (well, compiler settings perhaps, but that’s it). In mine I only have this now:

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
CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function 

I´m using R v4.0.0 on macOS Catalina 10.15.2. and I´m still facing the same problem.

clang-7: error: no such file or directory: ‘/Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib’
make: *** [rstan.so] Error 1
ERROR: compilation failed for package ‘rstan’

  • removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan’
  • restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

The .R/Makevars file contains

`#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`

. I also tried

but to no avail and showed error -
/usr/local/clang7/include/c++/v1/stdlib.h:94:15: fatal error: 'stdlib.h' file not found #include_next <stdlib.h>

Any pointers to rectify this problem ?

I think you’re not using the Xcode compiler? I don’t have a clang-7 on my OS X.

Typing this, g++ --version in the terminal gives this,


Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Yes,
Command g++ --version in terminal shows a similar output.
How can i fix this issue?

Please paste your output here. Saying “similar output” means that they are not the same and that gets me curious…

Apologies, its the exact same output

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

The above seems to be the problem. Have you removed all traces of the previous installation (clang7)? I don’t have that file on my laptop anymore…

Just to clarify,

Do you have anything in your:

~/.Rprofile, ~/.Renviron, or ~/.R/Makevars files? If so, what are they?

My guess is, you have something in ~/.Renviron and shouldn’t.

I’m running into Stan compilation errors using R 4.0 on Catalina. After doing a full uninstall and reinstall of R via homebrew, and installing the latest rmacoslib/r-macos-rtools, I was able to build rstan from source. However, this code (from Rethinking)

library(rethinking)
data("Trolley")
d <- Trolley

m11.1stan <- map2stan(
  alist(
    response ~ dordlogit(phi, cutpoints),
    phi <- 0,
    cutpoints ~ dnorm(0, 10)
  ), data= list(response = d$response),
  start = list(cutpoints = c(-2, -1, 0, 1, 2, 2.5)),
  chains = 2
)

Returns this error:

[1] “Error in sampler$call_sampler(args_list[[i]]) : " " c++ exception (unknown reason)”
error occurred during calling the sampler; sampling not done
Stan model ‘3c90bc124a98feb7f95b344e406697bc’ does not contain samples.
Error in names(coef) <- names(start[[1]]) :
attempt to set an attribute on NULL

I get the same error with a blank Makevars file and with @torkar’s Makevars (copied with a slight modification just based on which version of x86_64-apple-darwin lives in the gcc folder):

FC = /usr/local/gfortran/bin/gfortran
FLIBS = -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function

One notable difference is that, while I know I have gcc/g++ version 9 and clang/clang++ version 11 installed, g++ --version does not return what others have said it’s supposed to:

g++ (GCC) 4.9.2 20141029 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Which is obviously wrong, but I’m not sure how to convince my computer that it has newer compilers it should be using (fwiw, when I build packages, R does seem to be calling gcc 9).

Thoughts?