Rcpp 警告:“找不到选项‘-L/usr/local/Cellar/gfortran/4.8.2/gfortran’的目录"; [英] Rcpp warning: "directory not found for option '-L/usr/local/Cellar/gfortran/4.8.2/gfortran'"

查看:106
本文介绍了Rcpp 警告:“找不到选项‘-L/usr/local/Cellar/gfortran/4.8.2/gfortran’的目录";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与其他一些问题有关,例如 RccpArmadilloelement-wise-multiplication.

This question relates to some others out there, like RccpArmadillo or element-wise-multiplication.

但是,我的设置是这样的,我不知道我必须编辑/simlink 什么才能使 Rccp 运行而不给我警告.

However, my settings are such that I do not know what I have to edit/simlink to make Rccp run without giving me warnings.

我使用的是最新 R 版本的 Mac 10.9(小牛).

I am on an Mac 10.9 (mavericks) using the latest R version.

一开始,尝试使用我从这里获得的以下代码 RccpvsR,出现错误:

At the very beginning, trying the following code I got from here RccpvsR, I got an error:

ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)`  

然后,基于 RccpArmadillo 我做了以下事情:

Then, based on RccpArmadillo I did the following:

# Update FLIBS in ~/.R/Makevars
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
#Re-Install from source
install.packages(c("Rcpp","RcppArmadillo","inline"),type="source")
#Restart R

这只是尝试一下,因为我没有 /usr/local/Cellar/gfortran/ 目录.事实上,我所有的 libgfortran* 文件都在这里(在 macports 目录中):

this was JUST trying things out since I have NO /usr/local/Cellar/gfortran/ directory. In fact, all my libgfortran* files are here (At the macports dir):

>ls /opt/local/lib/gcc48/libgfortran.*
/opt/local/lib/gcc48/libgfortran.3.dylib       /opt/local/lib/gcc48/libgfortran.dylib
/opt/local/lib/gcc48/libgfortran.a       /opt/local/lib/gcc48/libgfortran.spec

和这里 /opt/local/lib/gcc48/gcc/x86_64-apple-darwin13/4.8.3/libgfortranbegin.a 我在任何地方都没有 gfortran 文件.

and here /opt/local/lib/gcc48/gcc/x86_64-apple-darwin13/4.8.3/libgfortranbegin.a and I have no gfortran file anywhere.

然后我尝试了代码 RccpvsR 再次出人意料,它奏效了!除了我收到警告这一事实之外:

Then I tried the code RccpvsR again and surprisingly, it worked!. Apart from the fact that I get a warning:

ld: warning: directory not found for option '-L/usr/local/Cellar/gfortran/4.8.2/gfortran' 

因为它当然不存在,但是由该代码创建的函数 cosineRcpp 运行没有问题.

because of course, it does not exists, but the function created by that code, cosineRcpp, runs with no problems.

因此,所有这些,请问是否有人知道我是否必须将 /opt/local/lib/gcc48/ 中的 libgfortran 文件模拟链接为:

Therefore, all that, to ask if anyone knows if I have to simlink the libgfortran files at /opt/local/lib/gcc48/ as:

ln -s /opt/local/lib/gcc48/libgfortran.* /usr/local/lib/

然后删除/编辑该行:

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

~/.R/Makevars

或者如果我必须安装新的东西.

or if I have to install something new.

提前感谢您的时间!

推荐答案

简答

只需将libgfortran的路径放入FLIBS中,例如

FLIBS=-L/opt/local/lib/gcc48/

或者,将其中的文件符号链接到 /usr/local/lib/,如果您对此感到满意.但是,此解决方案非常脆弱,因为如果您更新 gfortran 或将其移动到其他目录,很容易忘记更新此路径.

Or, symlink the files within to /usr/local/lib/, if you're comfortable with that. This solution is, however, quite brittle as it's easy to forget to update this path if you update gfortran, or move it to a different directory.

您可以查询 gfortran 以获取 libgfortran.dylib 的路径,例如

You can query gfortran for the path to libgfortran.dylib as e.g.

gfortran -print-file-name=libgfortran.dylib

您可以直接在 Makevars 文件中执行此操作;例如

You can just execute this directly in your Makevars file; e.g.

FLIBS = -L`gfortran -print-file-name=libgfortran.dylib | xargs dirname`

<小时>

过时的长答案

尝试直接从 gfortran 输出解析适当的 FLIBS.

首先介绍一下背景./usr/local/Cellar 目录是包管理器 homebrew 使用的默认路径对于 OS X.将其视为 macports 的替代品.

First, some background. The /usr/local/Cellar directory is the default path used by homebrew, a package manager for OS X. Think of it as an alternative to macports.

Homebrew 现在提供 gfortran 及其相关库作为 gcc 包的一部分,因此它安装 FORTRAN 库的路径现在已更改.但是,这些(通常)可以使用 gfortran -print-search-dirs 发现.例如,在我的系统上,

Homebrew now provides gfortran and its associated libraries as part of the gcc package, and so the paths where it installs FORTRAN libraries has now changed. However, these can (in general) be discovered using gfortran -print-search-dirs. For example, on my system,

gfortran -print-search-dirs

会给我

install: /usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/
programs: =/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/bin/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/bin/
libraries: =/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../:/lib/x86_64-apple-darwin14.0.0/4.9.2/:/lib/:/usr/lib/x86_64-apple-darwin14.0.0/4.9.2/:/usr/lib/

拆分,并用 R 打印,我明白了:

Split, and printed with R, I see:

[[1]]
[1] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/"

[[2]]
[1] "/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/"                                                                                    
[2] "/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/"                                                                                    
[3] "/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/"                                                                                          
[4] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/"                                                                                
[5] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/"                                                                                      
[6] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/bin/x86_64-apple-darwin14.0.0/4.9.2/"
[7] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/bin/"                                

[[3]]
[1] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/"                                                                                
[2] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/x86_64-apple-darwin14.0.0/4.9.2/"
[3] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/"                                
[4] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../x86_64-apple-darwin14.0.0/4.9.2/"                                       
[5] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../"                                                                       
[6] "/lib/x86_64-apple-darwin14.0.0/4.9.2/"                                                                                                                         
[7] "/lib/"                                                                                                                                                         
[8] "/usr/lib/x86_64-apple-darwin14.0.0/4.9.2/"                                                                                                                     
[9] "/usr/lib/"  

就我而言,libgfortran 实际上就在这里:

In my case, libgfortran actually lives here:

/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../

这就是我们想要传递给 FLIBS 的路径.但是,把它拉出来有点痛苦,所以让我们告诉 FLIBS 使用 gfortran 通常使用的任何路径:

And so this is the path we want to pass to FLIBS. But, pulling that out is kind of a pain, so let's just tell FLIBS to use whatever paths are normally used by gfortran:

gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||'

这很好,但我们希望库路径的格式适合编译器;即,带有 -L 前缀.让我们用 sed 做到这一点:

This is nice, but we want the library paths in a format suitable for the compiler; ie, with -L prepended. Let's do that with sed:

gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'

此输出(拆分以提高可读性)

This outputs (split for readability)

-L/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/
-L/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/x86_64-apple-darwin14.0.0/4.9.2/
-L/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/
-L/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../x86_64-apple-darwin14.0.0/4.9.2/
-L/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../
-L/lib/x86_64-apple-darwin14.0.0/4.9.2/
-L/lib/
-L/usr/lib/x86_64-apple-darwin14.0.0/4.9.2/
-L/usr/lib/

总而言之,这意味着以下内容应该适用于您,至少在 OS X 上,但(通常)应该(通常)适用于具有 gfortran 的任何平台(只要它在 PATH):

All together, this implies that the following should work for you, at least on OS X, but should (in general) work on any platform with gfortran (as long as it's on the PATH):

FLIBS=`gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'`

这并不完美,例如如果您的路径中有空格,它将会失败——如果您这样做,1) 你应得的,2) 它也应该是一个相对"容易的修复.

This isn't perfect, e.g. it will fail if you have spaces in your paths -- if you do, 1) you deserve what you get and 2) it should also be a 'relatively' easy fix.

这篇关于Rcpp 警告:“找不到选项‘-L/usr/local/Cellar/gfortran/4.8.2/gfortran’的目录";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆