使用 devtools::install_github() 安装无法检测到构建工具

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

这是我第一次尝试下载 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、clang4 和 gfortran。现在我收到一条弹出消息:

“安装构建工具 从源代码构建 R 包需要安装额外的构建工具。 您想现在安装附加工具吗? 是/否”

如果我单击“否”,我会收到此错误:

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
r github devtools
2个回答
3
投票

看起来安装此软件包需要克服一些问题(首先是 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 安装 gcc 和 llvm(安装 Homebrew 的说明),或者,如果您已经通过 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(回复:https://stackoverflow.com/a/65334247/12957340),你可以从 https:// 下载它github.com/fxcoudert/gfortran-for-macOS/releases/tag/10.2-bigsur-intel

更新(2022/04/05)

我在更新“RcppAlgos”时遇到错误(找不到 gmp.h 或 libgmp)。我检查了 gmp 是否已安装(

brew install gmp
),然后在 ~/.R/Makevars 文件中将 /usr/local/include 添加到 CPPFLAGS 并将 /usr/local/lib 添加到 LDFLAGS 以解决问题,即

cat ~/.R/Makevars
LOC=/usr/local/gfortran
CC=$(LOC)/bin/gcc -fopenmp
CXX=$(LOC)/bin/g++ -fopenmp
CXX11 = $(LOC)/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$(LOC)/lib -Wl,-rpath,$(LOC)/lib,-L/usr/local/lib
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/include

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++

0
投票

我也面临着同样的问题。建议的解决方案在步骤#5 之前运行良好。

来自@jared_mamrot:

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

就我而言,~/.R/Makevars 文件已经存在。我可以在哪里保存新的(仍然可以通过 R 访问)?

谢谢!

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