这是我第一次尝试下载 Github 包,在 MacOS Big Sur v11.2.1 上使用 RStudio v1.2.5033 时遇到了一些问题。
最初,当运行
library(devtools)
devtools::install_github('xuyiqing/gsynth')
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Warning in install.packages :
installation of package ‘gsynth’ had non-zero exit status
Run Code Online (Sandbox Code Playgroud)
看了一些资料,看来我需要下载命令行工具,所以我下载了 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.
Run Code Online (Sandbox Code Playgroud)
在 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
Run Code Online (Sandbox Code Playgroud)
看起来安装此软件包需要克服一些问题(首先是 xcode 命令行工具和 OpenMP 支持),但如果按照此处的说明进行操作,则应该克服这些问题:https://stackoverflow.com/a /65334247/12957340
进行必要的更改后,我成功在我的系统(macOS Big Sur 11.2.3 / R 版本 4.0.3)上安装了 gsynth,devtools::install_github('xuyiqing/gsynth')没有出现任何问题。
--
以下是万一上述链接失效时的说明:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
Run Code Online (Sandbox Code Playgroud)
# This can take several hours
brew install gcc
brew install llvm
Run Code Online (Sandbox Code Playgroud)
brew cleanup
brew update
brew upgrade
brew reinstall gcc
brew reinstall llvm
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
~/.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
Run Code Online (Sandbox Code Playgroud)
# To check whether openmp is enabled, compile data.table:
install.packages("data.table", type = "source")
Run Code Online (Sandbox Code Playgroud)
我在更新“RcppAlgos”时遇到错误(找不到 gmp.h 或 libgmp)。我检查了 gmp 是否已安装(brew install gmp),然后将 /usr/local/include 添加到 CPPFLAGS 并将 /usr/local/lib 添加到 ~/.R/Makevars 文件中的 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++
Run Code Online (Sandbox Code Playgroud)