Rcpp警告:“;找不到选项'-L/usr/local/Cellar/gfortran/4.8.2/gfortran'&引用;

Rcpp警告:“;找不到选项'-L/usr/local/Cellar/gfortran/4.8.2/gfortran'&引用;,r,rcpp,R,Rcpp,这个问题与其他一些问题有关,比如或 但是,我的设置是这样的,我不知道我必须编辑什么/simlink才能使Rccp运行而不给我警告 我在Mac10.9(mavericks)上使用最新的R版本 一开始,我尝试从这里获得的以下代码时,出现了一个错误: ld: library not found for -lgfortran clang: error: linker command failed with exit code 1 (use -v to see invocation)` 然后,根据我

这个问题与其他一些问题有关,比如或

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

我在Mac10.9(mavericks)上使用最新的R版本

一开始,我尝试从这里获得的以下代码时,出现了一个错误:

ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)`  
然后,根据我所做的以下工作:

# 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/ceral/gfortran/
目录。事实上,我所有的
libgfortran*
文件都在这里(在macports目录中):

这里是
/opt/local/lib/gcc48/gcc/x86_64-apple-darwin13/4.8.3/libgfortranbegin.a
,我没有
gfortran
文件

然后我再次尝试了代码,令人惊讶的是,它成功了!。除了我得到警告之外:

ld: warning: directory not found for option '-L/usr/local/Cellar/gfortran/4.8.2/gfortran' 
因为它当然不存在,但是由该代码创建的函数,
cosineRcpp
,运行起来没有问题

因此,所有这些,询问是否有人知道我是否必须将
/opt/local/lib/gcc48/
上的
libgfortran
文件简单链接为:

ln -s /opt/local/lib/gcc48/libgfortran.* /usr/local/lib/
然后删除/编辑该行:

FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
~/.R/Makevars

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

提前感谢您的时间

简短回答 只需将
libgfortran
的路径放入
FLIBS
,例如

FLIBS=-L/opt/local/lib/gcc48/
或者,如果您愿意的话,将中的文件符号链接到
/usr/local/lib/
。但是,此解决方案非常脆弱,因为如果您更新
gfortran
,或者将其移动到其他目录,很容易忘记更新此路径

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

gfortran -print-file-name=libgfortran.dylib
您可以直接在
Makevars
文件中执行此操作;e、 g

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

过时的长答案 尝试直接从
gfortran
输出解析适当的
FLIBS

首先是一些背景。
/usr/local/cillar
目录是OS X软件包管理器使用的默认路径。可以将其视为
macports
的替代品

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

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打印,我看到:

[[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
实际上住在这里:

/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
通常使用的任何路径:

gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||'
这很好,但我们希望库路径的格式适合编译器;即,前面加了
-L
。让我们使用
sed

gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'
此输出(为了可读性而拆分)

总之,这意味着至少在OS X上,以下各项应该适用于您,但(通常)应该适用于具有
gfortran
(只要它位于
路径上)的任何平台:


这并不是完美的,例如,如果你的路径中有空格,它将失败——如果你有空格,1)你应该得到你应得的,2)它也应该是一个“相对”容易的修复方法。

对@kevin ushey的答案(至少我需要;我使用Prezto)的一个小调整是在
grep'^libraries:
中添加单引号,结果是:

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

将这一行添加到我的
~/.R/Makevars
文件中就成功了

你在OSX上是偶然的吗?你可以在r-sig-mac中询问;我认为您需要Xcode命令行工具或其他东西。rcpp-devel列表也可能有所帮助。我在Linux上,这些东西“只起作用”。是的,我编辑了这个问题。我使用的是Mac10.9.5,使用的是最新的R版本。我还安装了Xcode。无论如何谢谢你!查看Simon的“Mac上的R”页面了解gfortran。我想你可能需要安装其他东西。仅仅安装Xcode是不够的。您现在(我认为是OSX 10.7之后)需要额外安装命令行工具(从Xcode中)。ATT网站上提供的gfortran版本是gfortran-4.2.3,它警告您大多数其他版本都不完整,并特别警告不要使用HPC版本(不管是什么版本)。@BondedDust:我相信我已经安装了命令行工具,因为我过去需要/使用过它。我稍后会在家里检查,但我很确定我有。哦,男孩:)谢谢你提供的所有细节。我们是否应该更新Rcpp常见问题解答中的相应问题?@kevin Ushey:我知道自制软件,但因为我从未使用过它,所以我不知道默认目录是
/usr/local/ceral
。现在,我喜欢你的简短答案(它有效),我真的,真的喜欢你的长答案(它也有效)。非常感谢你的帮助!
-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/
FLIBS=`gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'`
FLIBS=`gfortran -print-search-dirs | grep '^libraries:' | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'`