编译R包samr时出错:`ld:找不到-lgfortran的库`

编译R包samr时出错:`ld:找不到-lgfortran的库`,r,macos,gcc,fortran,gfortran,R,Macos,Gcc,Fortran,Gfortran,我正在尝试install.packages(“samr”),但它似乎在尝试使用Fortran编译文件,但我的Fortran似乎不在安装程序指定的路径上,我的Fortran来自brew install gcc(我相信正确的路径是/usr/local/cillar/gcc/7.1.0/lib/gcc/7)。这是我的错误消息: install.packages("samr") --- Please select a CRAN mirror for use in this session --- Pac

我正在尝试
install.packages(“samr”)
,但它似乎在尝试使用Fortran编译文件,但我的Fortran似乎不在安装程序指定的路径上,我的Fortran来自
brew install gcc
(我相信正确的路径是
/usr/local/cillar/gcc/7.1.0/lib/gcc/7
)。这是我的错误消息:

install.packages("samr")
--- Please select a CRAN mirror for use in this session ---
Package which is only available in source form, and may need
  compilation of C/C++/Fortran: ‘samr’
Do you want to attempt to install these from sources?
y/n: y
installing the source package ‘samr’

trying URL 'https://cloud.r-project.org/src/contrib/samr_2.0.tar.gz'
Content type 'application/x-gzip' length 36702 bytes (35 KB)
==================================================
downloaded 35 KB

* installing *source* package ‘samr’ ...
** libs
gfortran   -fPIC  -g -O2  -c rankcol.f -o rankcol.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o samr.so rankcol.o -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [samr.so] Error 1
ERROR: compilation failed for package ‘samr’
* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/samr’

The downloaded source packages are in
    ‘/private/var/folders/v_/n5nqr5812074ct0zkldqhg500000gn/T/RtmpBn8P5n/downloaded_packages’
Warning message:
In install.packages("samr") :
  installation of package ‘samr’ had non-zero exit status

它看起来像是一个特定于环境的问题。我每天都在使用R 3.3.3,并且我能够安装该软件包,没有任何问题:

# this one is required by samr and is no longer available via CRAN
source("https://bioconductor.org/biocLite.R")
biocLite("impute")
# samr, itself, can be installed from CRAN
install.packages("samr")
library(samr)
但是,我使用的gfortran安装略有不同-直接从源代码:

这就是从项目页面安装gfortran时的位置

> which gfortran
/usr/local/bin/gfortran
> ls -l /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/ | wc -l
      20

也许你可以试着从项目页面安装它?不幸的是,对于macOS,在R包(特别是Java和Fortran)中有很多强有力的假设。

感谢您的回答,我基本上做了同样的事情,并且成功了。在此之前,我也尝试过直接从他们的页面下载并安装它,但一直存在版本问题。但是安装gcc.gnu.org中指定的gfortran似乎是解决方案。酷!享受Fortran的乐趣!;)。哦。
> which gfortran
/usr/local/bin/gfortran
> ls -l /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/ | wc -l
      20