Compilation failed for package ‘readxl’ on Mac using source from PPPM (even though other packages compile)

I am repeatedly hitting an error installing version 1.3.1 of the readxl package (from source) on MacOS 12.6.5 (Monterey).

I downloaded the .tar.gz for version 1.3.1 from Posit Public Package Manager (

I'm able to compile other older package versions from source, but readxl results in many lines with errors like

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:625:29: error: 'gid_t' has not been declared
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/select.h:114:23: error: 'fd_set' has not been declared
and ends in
make: *** [XlsWorkSheet.o] Error 1
ERROR: compilation failed for package ‘readxl’

Here is what I have verified so far - any suggestions for how to unblock this are appreciated:

  • Verified that a version of gcc is installed (gcc11), other packages can compile from source (using gcc), and and that flags are set in the Makevars file referencing the correct version of gcc (see below)
  • Verified that MacOS Command Line Tools are installed, with a relatively recent version (see below)
  • Verified that Rcpp is installed (since readxl lists this as a requirement for "LinkingTo")
  • Verified that other related packages can install - xlsx, and xlsxjars installed without issue

Command Line Tools and clang info
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X Snow Leopard 12.6.5

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1]
compiler_3.6.1 tools_3.6.1

Makefile info

In the 15 years I’ve been using R with macOS I’ve never hesitated to choose the option to install from source. Slowly, it dawned on me that I was spending way to much time debugging and not enough time doing data analysis. I still take the option, but with a one strike rule. If I get a failure, settle for binary is what I do.

There are several potential issues here.

For one, I would stick to the Apple compilers, instead of using gcc from brew. That is not tested, and may very well fail, especially for older R versions.

Two, the CRAN binary packages were moved to a different server, so if you want to install a binary package, CRAN actually has a binary for readxl 1.3.1:

  repos = "", 
  type = "binary"

Three, I can install readxl 1.4.2 fine from source on R 3.6.3:

❯ install.packages("readxl", type = "source")
Installing package into ‘/Users/gaborcsardi/Library/R/3.6/library’
(as ‘lib’ is unspecified)
trying URL ''
Content type 'application/x-gzip' length 2091835 bytes (2.0 MB)
downloaded 2.0 MB
  • installing source package ‘readxl’ ...
    ** package ‘readxl’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** libs
    clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c cpp11.cpp -o cpp11.o
    clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c XlsWorkBook.cpp -o XlsWorkBook.o
    clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c XlsxWorkBook.cpp -o XlsxWorkBook.o
    clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c zip.cpp -o zip.o
    clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c Read.cpp -o Read.o
    clang -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c cran.c -o cran.o
    clang -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c libxls/xlstool.c -o libxls/xlstool.o
    clang -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c libxls/endian.c -o libxls/endian.o
    clang -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c libxls/ole.c -o libxls/ole.o
    clang -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c libxls/xls.c -o libxls/xls.o
    clang -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/include" -DNDEBUG -Iunix -I. -I"/Users/gaborcsardi/Library/R/3.6/library/cpp11/include" -I"/Users/gaborcsardi/Library/R/3.6/library/progress/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c libxls/locale.c -o libxls/locale.o
    clang++ -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Versions/3.6/Resources/lib -L/usr/local/lib -o cpp11.o XlsWorkBook.o XlsxWorkBook.o zip.o Read.o cran.o libxls/xlstool.o libxls/endian.o libxls/ole.o libxls/xls.o libxls/locale.o -F/Library/Frameworks/R.framework/Versions/3.6 -framework R -Wl,-framework -Wl,CoreFoundation
    installing to /Users/gaborcsardi/Library/R/3.6/library/00LOCK-readxl/00new/readxl/libs
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    *** copying figures
    ** building package indices
    ** installing vignettes
    ** testing if installed package can be loaded from temporary location
    ** checking absolute paths in shared objects and dynamic libraries
    ** testing if installed package can be loaded from final location
    ** testing if installed package keeps a record of temporary installation path
  • DONE (readxl)

The downloaded source packages are in

So I would try removing the custom Makevars, unless you really need to use it for some reason.

Btw. I can also install readxl 1.3.1 from source:

  repos = NULL, 
  type = "source"
❯ clang --version
Apple clang version 14.0.3 (clang-1403.
Target: arm64-apple-darwin22.3.0
Thread model: posix
InstalledDir: /Applications/

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.