这个问题与其他一些问题有关,比如RccpArmadillo或element-wise-multiplication.
但是,我的设置是这样的,我不知道我有什么编辑/ simlink使Rccp运行而不给我警告.
我使用最新的R版本在Mac 10.9(小牛队)上.
在一开始,尝试从RCCpvsR得到的以下代码,我收到一个错误:
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)`
Run Code Online (Sandbox Code Playgroud)
然后,基于RccpArmadillo,我做了以下事情:
# 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
Run Code Online (Sandbox Code Playgroud)
这是因为我没有/usr/local/Cellar/gfortran/目录所以只是尝试了.事实上,我的所有libgfortran*文件都在这里(在macports目录下):
>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
Run Code Online (Sandbox Code Playgroud)
在这里/opt/local/lib/gcc48/gcc/x86_64-apple-darwin13/4.8.3/libgfortranbegin.a,我没有任何gfortran文件.
然后我再次尝试了代码RccpvsR,令人惊讶的是,它工作了!除了我得到警告的事实:
ld: warning: directory not found for option '-L/usr/local/Cellar/gfortran/4.8.2/gfortran'
Run Code Online (Sandbox Code Playgroud)
因为它当然不存在,但是该代码创建的函数cosineRcpp运行没有问题.
因此,所有这些,要问是否有人知道我是否必须将libgfortran文件链接/opt/local/lib/gcc48/为:
ln -s /opt/local/lib/gcc48/libgfortran.* /usr/local/lib/
Run Code Online (Sandbox Code Playgroud)
然后删除/编辑该行:
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
Run Code Online (Sandbox Code Playgroud)
在 ~/.R/Makevars
或者如果我必须安装新的东西.
在此先感谢您的时间!
Kev*_*hey 17
只需将路径libgfortran放入FLIBS,例如
FLIBS=-L/opt/local/lib/gcc48/
Run Code Online (Sandbox Code Playgroud)
或者,/usr/local/lib/如果您对此感到满意,请将文件符号链接到.但是,此解决方案非常脆弱,因为如果更新gfortran或将其移动到其他目录,很容易忘记更新此路径.
您可以查询例如gfortran路径libgfortran.dylib
gfortran -print-file-name=libgfortran.dylib
Run Code Online (Sandbox Code Playgroud)
您可以直接在Makevars文件中执行此操作; 例如
FLIBS = -L`gfortran -print-file-name=libgfortran.dylib | xargs dirname`
Run Code Online (Sandbox Code Playgroud)
尝试FLIBS直接从gfortran输出中解析适当的.
首先,一些背景.该/usr/local/Cellar目录是homebrew使用的默认路径,它是OS X的包管理器.可以将其视为替代macports.
Homebrew现在提供gfortran及其相关的库作为gcc包的一部分,因此它安装FORTRAN库的路径现在已经改变.但是,这些(通常)可以使用gfortran -print-search-dirs.例如,在我的系统上,
gfortran -print-search-dirs
Run Code Online (Sandbox Code Playgroud)
会给我的
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/
Run Code Online (Sandbox Code Playgroud)
拆分,并用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/"
Run Code Online (Sandbox Code Playgroud)
就我而言,libgfortran实际上住在这里:
/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../
Run Code Online (Sandbox Code Playgroud)
所以这就是我们想要传递的路径FLIBS.但是,拉出来是一种痛苦,所以让我们告诉FLIBS使用通常使用的任何路径gfortran:
gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||'
Run Code Online (Sandbox Code Playgroud)
这很好,但我们希望库路径的格式适合编译器; 即,与-L前置.让我们这样做sed:
gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'
Run Code Online (Sandbox Code Playgroud)
输出(分开以便于阅读)
-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/
Run Code Online (Sandbox Code Playgroud)
总之,这意味着以下内容应该适合您,至少在OS X上,但应该(通常)在任何平台上工作gfortran(只要它在上面PATH):
FLIBS=`gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'`
Run Code Online (Sandbox Code Playgroud)
这并不完美,例如,如果你的路径中有空格,它就会失败 - 如果你这样做,1)你应该得到你所得到的东西; 2)它也应该是一个"相对"的简单修复.