Here is my steps to solve the problem:
- Update Xcode to the newest version.
- In terminal:
xcode-select —install
(install the Xcode CLI) - Install the r-macos-rtools by @coatless
- In Finder: Go → Go to Folders… → ~/.R/Makevars and modify the Makevars file as @wds15’s suggestion :
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
- (Maybe optional)In R: upgrade to R 3.6.1, remove rstan and StanHeaders (maybe optional) and reinstall rstan:
remove.packages(“rstan”)
remove.packages(“StanHeaders”)
file.remove(“.RData”)
restart R
install.packages(“rstan”, dependencies = TRUE)