R语言 使用devtools::install_github()进行安装时无法检测构建工具

tf7tbtn2  于 2022-12-06  发布在  Git
关注(0)|答案(1)|浏览(567)

这是我第一次尝试下载Github软件包,我在MacOS Big Sur v11.2.1上使用RStudio v1.2.5033遇到了一些麻烦。
最初,运行时

library(devtools)
devtools::install_github('xuyiqing/gsynth')

我得到这个错误:

Warning in install.packages :
  installation of package ‘gsynth’ had non-zero exit status

我看了一些资料,似乎需要下载命令行工具,所以我下载了XCode CLI、clang 4和gfortran。现在我看到一个弹出消息,说:
“从源安装生成工具Building R包需要安装其他生成工具。是否要立即安装其他工具?Y/N”
如果我单击“否”,我会收到此错误:

Error: Failed to install 'gsynth' from GitHub:
  Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.

在一个R控制台中运行上面的pkgbuild代码,得到的结果如下:

Trying to compile a simple C file
Error: Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.
rror: Could not find tools necessary to compile a package
0mkxixxg

0mkxixxg1#

看起来您需要克服一些问题才能安装此软件包(首先是xcode命令行工具和OpenMP支持),但如果您按照以下说明操作,应该可以克服这些问题:https://stackoverflow.com/a/65334247/12957340
在进行了必要的更改后,我使用devtools::install_github('xuyiqing/gsynth')成功地在我的系统(macOS Big Sur 11.2.3 / R版本4.0.3)上安装了gsynth,没有出现任何问题。

下面是上面的链接失效时的说明:
1.重新安装xcode命令行工具(即使它显示“最新”)

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

1.通过Homebrew(instructions for installing Homebrew)安装gcc和llvm,如果您已经通过Homebrew安装了gcc/llvm,请跳到下一步

# This can take several hours
brew install gcc
brew install llvm

1.通过Homebrew安装gcc和llvm后:

brew cleanup
brew update
brew upgrade
brew reinstall gcc
brew reinstall llvm

1.将一些标题链接到/usr/local/include

sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/

# You can safely ignore warnings like this:
#ln: /usr/local/include//tcl.h: File exists
#ln: /usr/local/include//tclDecls.h: File exists
#ln: /usr/local/include//tclPlatDecls.h: File exists
#ln: /usr/local/include//tclTomMath.h: File exists
#ln: /usr/local/include//tclTomMathDecls.h: File exists
#ln: /usr/local/include//tk.h: File exists
#ln: /usr/local/include//tkDecls.h: File exists
#ln: /usr/local/include//tkPlatDecls.h: File exists

1.创建一个新的~/.R/Makevars文件(如果您已经有一个~/.R/Makevars文件,请将其保存在另一个目录中(远离~/.R/)),并在该文件中仅包括以下行:

FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX1X=/usr/local/gfortran/bin/g++
CXX98=/usr/local/gfortran/bin/g++
CXX11=/usr/local/gfortran/bin/g++
CXX14=/usr/local/gfortran/bin/g++
CXX17=/usr/local/gfortran/bin/g++

LLVM_LOC = /usr/local/opt/llvm
CC=/usr/local/gfortran/bin/gcc -fopenmp
CXX=/usr/local/gfortran/bin/g++ -fopenmp
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L/usr/local/opt/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I$(LLVM_LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include

1.在R/Rstudio中从源代码编译包

# To check whether openmp is enabled, compile data.table:
install.packages("data.table", type = "source")

1.如果您的软件包无法编译,那么一些SO用户必须安装一个新的gfortran(re:https://stackoverflow.com/a/65334247/12957340),您可以从https://github.com/fxcoudert/gfortran-for-macOS/releases/tag/10.2-bigsur-intel下载

相关问题