包安装错误:编译失败

Posted

技术标签:

【中文标题】包安装错误:编译失败【英文标题】:Package install error: compilation failed 【发布时间】:2014-06-01 21:01:33 【问题描述】:

我最近将 R 更新到 3.1.0。我试图将我的包移到 R.Framework 中的 3.1(我正在运行 OSX Mavericks)并且不知何故把它弄得一团糟,所以在全新安装之前完全卸载了所有东西。

在重新安装软件包时,我没有遇到任何问题,直到我点击了 forecast 软件包,这会产生以下错误:

     package ‘forecast’ is available as a source package but not as a binary

Warning in install.packages :
package ‘forecast’ is not available (for R version 3.1.0)

在重新安装之前,我实际上有 R 3.1.0 和 predict 和 hts 一起工作,所以我怀疑问题源于我所做的事情,而不是兼容性问题。

我运行了以下命令,看看是否可以发现有关安装失败的更多详细信息:install.packages("forecast", type = "source", verbose = T, quiet = F)

它的输出有点超出我的理解,但可能对诊断有帮助:

system (cmd0): /Library/Frameworks/R.framework/Resources/bin/R CMD INSTALL
trying URL 'http://cran.rstudio.com/src/contrib/forecast_5.3.tar.gz'
Content type 'application/x-gzip' length 150395 bytes (146 Kb)
opened URL
==================================================
downloaded 146 Kb

foundpkgs: forecast, /var/folders/0y/_13fkvws0tn5xh4m8wsymkdh0000gp/T//RtmpzTzSpG/downloaded_packages/forecast_5.3.tar.gz
files: /var/folders/0y/_13fkvws0tn5xh4m8wsymkdh0000gp/T//RtmpzTzSpG/downloaded_packages/forecast_5.3.tar.gz
* installing *source* package ‘forecast’ ...
** package ‘forecast’ successfully unpacked and MD5 sums checked
** libs
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"   -fPIC  -Wall -mtune=core2 -g -O2  -c calcBATS.cpp -o calcBATS.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"   -fPIC  -Wall -mtune=core2 -g -O2  -c calcTBATS.cpp -o calcTBATS.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"   -fPIC  -Wall -mtune=core2 -g -O2  -c etsTargetFunction.cpp -o etsTargetFunction.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"   -fPIC  -Wall -mtune=core2 -g -O2  -c etsTargetFunctionWrapper.cpp -o etsTargetFunctionWrapper.o
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"   -fPIC  -Wall -mtune=core2 -g -O2  -c etscalc.c -o etscalc.o
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"   -fPIC  -Wall -mtune=core2 -g -O2  -c etspolyroot.c -o etspolyroot.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"   -fPIC  -Wall -mtune=core2 -g -O2  -c makeBATSMatrices.cpp -o makeBATSMatrices.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"   -fPIC  -Wall -mtune=core2 -g -O2  -c makeTBATSMatrices.cpp -o makeTBATSMatrices.o
makeTBATSMatrices.cpp:11:6: warning: unused variable 'lengthSeasonal' [-Wunused-variable]
        int lengthSeasonal = 0;
            ^
1 warning generated.
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"   -fPIC  -Wall -mtune=core2 -g -O2  -c updateMatrices.cpp -o updateMatrices.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include"   -fPIC  -Wall -mtune=core2 -g -O2  -c updateTBATSMatrices.cpp -o updateTBATSMatrices.o
updateTBATSMatrices.cpp:38:10: warning: unused variable 'gammaVector' [-Wunused-variable]
        double *gammaVector;
                ^
1 warning generated.
clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o forecast.so calcBATS.o calcTBATS.o etsTargetFunction.o etsTargetFunctionWrapper.o etscalc.o etspolyroot.o makeBATSMatrices.o makeTBATSMatrices.o updateMatrices.o updateTBATSMatrices.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [forecast.so] Error 1
ERROR: compilation failed for package ‘forecast’
* removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/forecast’
Warning in install.packages :
  installation of package ‘forecast’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/0y/_13fkvws0tn5xh4m8wsymkdh0000gp/T/RtmpzTzSpG/downloaded_packages’

我真的很感谢这里的一些帮助。我最近编写的大部分代码都依赖于预测函数。

【问题讨论】:

看看 r-sig-mac 档案,里面有关于如何在 Mavericks 下编译 R 包的说明。 【参考方案1】:

这就是我所做的 (RcppArmadillo Compile Errors on OS X Mavericks)

    从 brew 安装 gfortran(如果你没有 brew,谷歌一下。安装很简单):

    brew install gfortran

    如果已安装,请使用以下命令升级到最新版本:

    brew upgrade gfortran

    然后执行以下操作之一:

    ln -s /usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.* /usr/local/lib/

    将此行添加到~/.R/Makevars 文件中:

    FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran

    我选择了第二个选项。

    现在再次运行install.packages("forecast", type = "source"),它应该可以工作了。

【讨论】:

【参考方案2】:

在我的例子中,我尝试使用devtools::install_github("robjhyndman/forecast") 安装最新版本的 forecast 包,但遇到了类似的错误。

然后,虽然我不确定我所做的是否正确,但按照 mchangun 的回答我做了如下并且错误得到了解决:

    brew upgrade gcc

错误:gcc 5.2.0 已安装

    gcc --version

配置为:--prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer /SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1 苹果 LLVM 版本 7.0.0 (clang-700.1.76) 目标:x86_64-apple-darwin15.0.0 线程模型:posix

    ls /usr/local/Cellar/gcc

4.9.2 4.9.2_1 5.2.0

    FLIBS=-L/usr/local/Cellar/gcc/5.2.0 行添加到~/.R/Makevars 文件中

    运行devtools::install_github("robjhyndman/forecast"),它成功了。

【讨论】:

【参考方案3】:

终端

    brew install gcc gcc --version ls /usr/local/Cellar/gcc 6.3.0_1 sudo vi /Library/Frameworks/R.framework/Resources/etc/Makeconf 添加行 FLIBS=-L/usr/local/Cellar/gcc/6.3.0_1

工作室:

    install.packages("预测"

【讨论】:

【参考方案4】:

从https://gcc.gnu.org/wiki/GFortranBinariesMacOS下载gfortran

sudo rm -r /usr/local/gfortran /usr/local/bin/gfortran

然后安装gfortran

sudo vi /Library/Frameworks/R.framework/Resources/etc/Makeconf

将所有 gfortran-4.8 更改为 gfortran

FC = gfortran FCFLAGS = -Wall -g -O2 $(LTO) FCLIBS = F77 = gfortran F77_VISIBILITY = FFLAGS = -g -O2 $(LTO)

FLIBS = -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 -lgfortran -lquadmath -lm

将 FLIBS 上方更改为下方

FLIBS = -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm

【讨论】:

【参考方案5】:

要安装 gfortran,请使用

brew cask install gfortran

【讨论】:

以上是关于包安装错误:编译失败的主要内容,如果未能解决你的问题,请参考以下文章

安装SQL2000时,出现错误“对于MSSQLServer服务,服务控制器操作失败:1726远程过程调用失败”,怎样解决?

安装VisualStudio时失败,错误信息安装包失败或证书不在有效期内

Gatsby new 安装锐包失败

包还原失败/.Net Core 安装错误

安装包 Beautiful Soup 失败。错误消息是“SyntaxError:调用'print'时缺少括号”

我在材料 ui 实现包中遇到了问题。我应该为这个错误安装哪个包?