0

I recently upgraded my R version to 4.1.1 using HomeBrew. After straightening out some path problems in R, I tried re-installing my old packages, but I get a very long series of errors which seem to have to do with C compilation. Here's what happens when I try to install a package:

> install.packages("utf8")
trying URL 'http://cran.r-project.org/src/contrib/utf8_1.2.2.tar.gz'
Content type 'application/x-gzip' length 240327 bytes (234 KB)
==================================================
downloaded 234 KB

* installing *source* package ‘utf8’ ...
** package ‘utf8’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
/usr/local/opt/llvm/bin/clang -fopenmp -I"/usr/local/Cellar/r/4.1.1/lib/R/include" -DNDEBUG 
  -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include -I/Library/Developer
/CommandLineTools/SDKs/MacOSX.sdk/usr/include 
 -Iutf8lite/src -fPIC  -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c as_utf8.c -o as_utf8.o
In file included from as_utf8.c:21:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:64:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:137:9: warning: 
      type nullability specifier '_Nullable' is a Clang
      extension [-Wnullability-extension]
        int     (* _Nullable _close)(void *);
                   ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:93:16: warning: 
      pointer is missing a nullability type specifier
      (_Nonnull, _Nullable, or _Null_unspecified)
      [-Wnullability-completeness]
        unsigned char   *_base;
                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:93:16: note: 
      insert '_Nullable' if the pointer may be null
        unsigned char   *_base;
                        ^
                          _Nullable 

[many similar errors omitted here]

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:220:5: error: 
      'TARGET_OS_IPHONE' is not defined, evaluates to 0
      [-Werror,-Wundef-prefix=TARGET_OS_]
#if TARGET_OS_IPHONE
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:385:25: warning: 
      type nullability specifier '_Nullable' is a Clang
      extension [-Wnullability-extension]
                 int (* _Nullable)(void *, cha...
                        ^

[Many similar messages omitted here]

21 warnings and 1 error generated.
make: *** [as_utf8.o] Error 1
ERROR: compilation failed for package ‘utf8’
* removing ‘/usr/local/Cellar/r/4.1.1/lib/R/library/utf8’

The downloaded source packages are in
    ‘/private/var/folders/9n/dw965k251pv8jzk_n62djdl80000gn/T/RtmpoZ1OqU/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning message:
In install.packages("utf8") :
  installation of package ‘utf8’ had non-zero exit status

The most I can figure out is that this has something to do with a failure to compile and link C code.

I'm running Mac OS 10.15.7 Catalina (the latest that my Mid-2012 MacBook Pro can run). However, I somehow seem to have the SDK for a newer version of Mac OS:

/Library/Developer/CommandLineTools/SDKs % ls
MacOSX.sdk  MacOSX10.15.sdk MacOSX11.1.sdk

and the default SDK (MacOSX.sdk) seems to link to the newer version (newer than my OS):

/Library/Developer/CommandLineTools/SDKs % ls -ltr .
total 0
lrwxr-xr-x  1 root  wheel   14 Oct  2 17:32 MacOSX.sdk -> MacOSX11.1.sdk
drwxr-xr-x  7 root  wheel  224 Oct  2 17:33 MacOSX11.1.sdk
drwxr-xr-x  8 root  wheel  256 Oct  2 17:34 MacOSX10.15.sdk

My R paths are the standard ones for Homebrew:

.libPaths()
[1] "/usr/local/Cellar/r/4.1.1/lib/R/library"
R.home()
[1] "/usr/local/Cellar/r/4.1.1/lib/R"

and I don't see anything obviously wrong with my path, which seems to contain gcc

echo $PATH
/usr/local/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:
/sbin:/Applications/VMware Fusion.app/Contents/Public:
/Library/TeX/texbin:/usr/local/share/dotnet:/opt/X11/bin:
~/.dotnet/tools:/Library/Apple/usr/bin

ls /usr/local/bin/gcc*
/usr/local/bin/gcc-11       /usr/local/bin/gcc-nm-11
/usr/local/bin/gcc-ar-11    /usr/local/bin/gcc-ranlib-11

Oddly, gcc seems to be set to compile using the 10.15 version of SDK, not the current 11.1 version:

gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr
 --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

For what it's worth, I also have this going on:

xcrun --show-sdk-path
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk

So I'm a bit confused about which version of the SDK is actually being used, etc.

My plan at the moment is to uninstall Xcode and reinstall version 12.4, which is the latest version you can run on 10.15 Catalina. I'm not sure if this will help.

Does anyone have any idea what the problem might be or how I might fix it? As of right now I basically can't use R, which is preventing me from doing virtually all of my work! Any help would be greatly appreciated.

Holt Dwyer
  • 51
  • 5
  • 1
    Is there a reason you need to use homebrew? Most of the problems I've seen installing R or packages come from interference from homebrew or conda. Things normally work great if you use the official R builds from CRAN. – MrFlick Oct 03 '21 at 02:27
  • Not particularly, but clearly the problem here is now with C compiling and not with R per se. – Holt Dwyer Oct 03 '21 at 02:52
  • Well, homebrew has everything setup to use their own build tools. All those paths with /usr/local aren't things you see when compiling packages using the standard R build. Plus, if you use the standard build, you can use the precompiled version so you don't have to compile anything yourself. These just don't look like the "normal' errors one sees when building packages. – MrFlick Oct 03 '21 at 02:59
  • 1
    Wow, you are absolutely right. I downloaded R directly from CRAN and not only did it not have any problem installing packages, but it also somehow still had access to a bunch of packages that I had had in a previous version. One more reason to never touch Homebrew, on top of its default behavior being to update absolutely everything on your computer every time you want to update one program...Thanks so much for the advice! – Holt Dwyer Oct 03 '21 at 06:31

0 Answers0