从 CRAN 存档安装 R 包时如何解决“致命错误:'stdlib.h'文件未找到”错误?

问题描述 投票:0回答:1

我正在尝试从 CRAN 存档安装 R 包“splusTimeDate”:

install.packages("https://cran.r-project.org/src/contrib/Archive/splusTimeDate/splusTimeDate_2.5.4.tar.gz", type="source", repos=NULL)

但是,我收到以下错误:

Installing package into ‘/Users/username/Library/R/arm64/4.3/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.r-project.org/src/contrib/Archive/splusTimeDate/splusTimeDate_2.5.4.tar.gz'
Content type 'application/x-gzip' length 151455 bytes (147 KB)
==================================================
downloaded 147 KB
* installing *source* package ‘splusTimeDate’ ...
** package ‘splusTimeDate’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C compiler: ‘clang version 14.0.6’
using SDK: ‘MacOSX13.3.sdk’
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include    -fPIC  -falign-functions=64 -Wall -g -O2  -c align.c -o align.o
In file included from align.c:19:
In file included from ./align.h:11:
In file included from ./timeUtils.h:16:
/Library/Frameworks/R.framework/Resources/include/R.h:43:11: fatal error: 'stdlib.h' file not found
# include <stdlib.h> /* Not used by R itself, but widely assumed in packages */
          ^~~~~~~~~~
1 error generated.
make: *** [align.o] Error 1
ERROR: compilation failed for package ‘splusTimeDate’
* removing ‘/Users/username/Library/R/arm64/4.3/library/splusTimeDate’
Warning in install.packages :
  installation of package ‘/var/folders/4z/tvbvjjk101qdx6y31dds68040000gq/T//Rtmp3fp00q/downloaded_packages/splusTimeDate_2.5.4.tar.gz’ had non-zero exit status

请帮助...我的博士依赖于我能够安装这个包及其反向依赖项和导入...! 😅

我正在使用 R(64 位芯片)版本 4.3.1 的 Apple M1 MacBook Pro 并已安装 xcode。

r cran
1个回答
0
投票

这可以通过提供 clang 所需的标头并将它们链接到

/usr/local/include
来解决。请禁用系统完整性保护 (SIP) 并执行以下操作:

sudo mkdir -p /usr/local/include
sudo ln -s $(xcrun --show-sdk-path)/usr/include/* /usr/local/include

您可能需要检查并备份 /usr/local/include 中存在的内容。

这是一个复杂的苹果问题,花了我很多时间来解决它。以下是一些相关链接:

© www.soinside.com 2019 - 2024. All rights reserved.