【问题标题】:Problem installing R package "ld: warning: directory not found for option "安装 R 包“ld:警告:找不到选项的目录”时出现问题
【发布时间】:2019-10-29 15:06:38
【问题描述】:

我正在尝试使用

在 R 中安装包 gradientForest
install.packages("gradientForest", repos="http://R-Forge.R-project.org")

我收到了这个错误

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

我已经尝试过 this thread 和 this thread 的答案。

根据这些线程,我使用

安装了 gcc
brew install gcc

我的 Makevars 看起来像

## With Rcpp 0.11.0 and later, we no longer need to set PKG_LIBS as there is
## no user-facing library. The include path to headers is already set by R.
#PKG_LIBS = 

## With R 3.1.0 or later, you can uncomment the following line to tell R to 
## enable compilation with C++11 (or even C++14) where available
CXX_STD = CXX17

VER=-9
CC=gcc$(VER)
CXX=g++$(VER)
CXX11=g++$(VER)
CXX14=g++$(VER)
CXX17=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L`gfortran -print-file-name=libgfortran.dylib | xargs dirname`

但不幸的是,它并没有改变我遇到的错误。 我的 R 版本是 3.6.1,我在 MacOS Catalina 上。

如果有人能帮助我,我将不胜感激。 谢谢

【问题讨论】:

    标签: r gcc clang gfortran macos-catalina


    【解决方案1】:

    遇到同样的编译错误。手动重新安装 Clang 和 GFortran 解决了我的问题。我使用的指令:R COMPILER TOOLS FOR RCPP ON MACOS

    (在 Catalina 10.15.3;R 3.6.2;RStudio 1.2.5 上)

    【讨论】:

    • 我使用位于此处的软件包安装程序安装了 gfortran:github.com/fxcoudert/gfortran-for-macOS/releases 我使用的是 M1 Mac mini,但能够成功安装并运行 Monterey (macOS 12) Intel 的构建。我没有尝试实验性 ARM 版本。
    【解决方案2】:

    以下是 R 官方文档中关于如何在 Mac 上安装 R 以及相关错误的 sn-p:

    
    CC = /usr/local/clang7/bin/clang
    CXX = /usr/local/clang7/bin/clang++
    CXX11 = $CXX
    CXX14 = $CXX
    CXX17 = $CXX
    CFLAGS = -g -O2 -Wall -pedantic -Wconversion -Wno-sign-conversion
    CXXFLAGS = -g -O2 -Wall -pedantic -Wconversion -Wno-sign-conversion
    CXX11FLAGS = $CXXFLAGS
    CXX14FLAGS = $CXXFLAGS
    CXX17FLAGS = $CXXFLAGS
    and gfortran by (El Capitan)
    
    FC = /usr/local/gfortran/bin/gfortran
    FLIBS = -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0
      -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
    or (Sierra or High Sierra)
    
    FC = /usr/local/gfortran/bin/gfortran
    FLIBS = -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0
      -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
    or (Mojave or later)
    
    FC = /usr/local/gfortran/bin/gfortran
    FLIBS = -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0
      -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
    (with lines broken here for legibility).
    
    If using the C/C++ compilers from the Command Line Tools (which do not have OpenMP support) one will need to include
    
    SHLIB_OPENMP_CFLAGS =
    SHLIB_OPENMP_CXXFLAGS =
    

    欲了解更多信息,请访问以下链接 6.3.2

    https://cran.r-project.org/doc/manuals/r-patched/R-admin.html

    这可能会对你有所帮助。

    【讨论】:

    • 接受并支持答案,如果它解决了问题
    猜你喜欢
    • 2019-02-17
    • 2012-03-16
    • 1970-01-01
    • 2017-12-31
    • 2016-06-30
    • 2013-06-08
    • 2019-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多