Cannot compile R packages with c++ code after updating to macOS Catalina

You likely need to reinstall command line tools — Apple often uninstalls them after OS updates. Try running:

xcode-select --install

in the terminal. (Note that, even if you’re using the R-provided LLVM toolchain, it will still require access to the default system headers, and those are installed as part of the command line tools toolchain)

EDIT: @coatless is spot on. In particular, from https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/, you need to set up your ~/.R/Makevars to point to the system headers:

mkdir -p ~/.R

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

Note that R 3.6.1 patched does this by default — e.g. I have in my $(R RHOME)/etc/Makeconf:

CPPFLAGS = -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

Leave a Comment

tech