0

我最近使用 HomeBrew 将我的 R 版本升级到了 4.1.1。在解决了 R 中的一些路径问题后,我尝试重新安装我的旧包,但我得到了一系列似乎与 C 编译有关的错误。这是我尝试安装软件包时发生的情况:

> 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 

[这里省略了许多类似的错误]

/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...
                        ^

[这里省略了许多类似的消息]

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

我能弄清楚的最多的是,这与无法编译和链接 C 代码有关。

我正在运行 Mac OS 10.15.7 Catalina(我的 2012 年中 MacBook Pro 可以运行的最新版本)。但是,不知何故,我似乎拥有适用于较新版本 Mac OS 的 SDK:

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

并且默认 SDK (MacOSX.sdk) 似乎链接到较新的版本(比我的操作系统更新):

/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

我的 R 路径是 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"

而且我没有看到我的路径有任何明显错误,它似乎包含 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

奇怪的是,gcc 似乎设置为使用 10.15 版本的 SDK 进行编译,而不是当前的 11.1 版本:

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

对于它的价值,我也有这样的事情:

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

所以我对实际使用的是哪个版本的 SDK 等感到有点困惑。

我目前的计划是卸载 Xcode 并重新安装 12.4 版本,这是您可以在 10.15 Catalina 上运行的最新版本。我不确定这是否会有所帮助。

有谁知道问题可能是什么或我该如何解决?截至目前,我基本上不能使用 R,这使我几乎无法完成所有工作!任何帮助将不胜感激。

4

0 回答 0