Mac: Failing to install any packages (i.e. Rcpp) after downloading RStudio: error: installation of package 'Rcpp' had non-zero exit status

Hi there,

I have just downloaded RStudio and installed the two packages clang.7.0.0 and gfortran-6.1.pkg on my Mac (iOS Catalina) 10.15. However, when trying to install any further package in RStudio I seem to run into the same error again and again. What do I need to do in order for it to work? The following code is for Rcpp because this is the first package I wanted to install in order to be able to import excel data sets.

Here's the code:

> install.packages('Rcpp')

  There is a binary version available
  but the source version is later:
     binary source needs_compilation
Rcpp  1.0.3  1.0.4              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) yes
installing the source package ‘Rcpp’

versuche URL ''
Content type 'application/x-gzip' length 2750216 bytes (2.6 MB)
downloaded 2.6 MB

* installing *source* package ‘Rcpp’ ...
** Paket ‘Rcpp’ erfolgreich entpackt und MD5 Summen überprüft
** using staged installation
** libs
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include/  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -Wall -g -O2  -c api.cpp -o api.o
clang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk' [-Wmissing-sysroot]
In file included from api.cpp:24:
In file included from ../inst/include/Rcpp.h:27:
In file included from ../inst/include/RcppCommon.h:29:
In file included from ../inst/include/Rcpp/r/headers.h:67:
In file included from ../inst/include/Rcpp/platform/compiler.h:100:
In file included from /Applications/
/Applications/ fatal error: 'math.h' file not found
#include_next <math.h>
1 error generated.
make: *** [api.o] Error 1
ERROR: compilation failed for package ‘Rcpp’
* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp’
Warning in install.packages :
  installation of package ‘Rcpp’ had non-zero exit status

The downloaded source packages are in

I have just started with R as my uni has shut down due to Covid-19 and I cannot use STATA anymore – and probably won't any longer once I have mastered R. For that I seem to really need your help and I would very much appreciate it!!!

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I create one? Using a reprex, complete with representative data will attract quicker and more answers. Only for future reference.

The error message

lang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk' [-Wmissing-sysroot]

shows that you don't have XCode's command line utility installed.

If you haven't already, download the free XCode app from the app store. Then from the command line

xcode-select --install

Be aware that MAC OS uses a non-standard compiler and programs to be installed by source sometimes throw the zero exit status error. If that happens, choose No to the Do you want to install from source and get the latest binary edition prepared by Saint Simon Urbanek of the Core R Team, who carries the brain damage burden of tweaking the code for us.

This was exactly what I needed to do for it to work! Thank you so much! I will post to the reprex next time, thanks for the advice!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.