构建 R 包并出现错误“ld: 找不到 -lgfortran”
我正在尝试安装 lars 软件包。 Ubuntu 11.04 Natty 64 位。从建筑物中我得到:
* 安装 *source* 包 âlarsâ ... ** 库 gfortran -fpic -O3 -pipe -g -c delcol.f -o delcol.o gcc -shared -o lars.so delcol.o -lgfortran -lm -L/usr/lib64/R/lib -lR /usr/bin/ld: 找不到 -lgfortran Collect2: ld 返回 1 退出状态 make: *** [lars.so] 错误 1 错误:包“lars”编译失败
gfortran 已安装,当我运行 gfortran --version
我得到
gfortran --版本 GNU Fortran (Ubuntu/Linaro 4.5.2-8ubuntu4)4.5.2
sudo ldconfig -v
给出错误
/sbin/ldconfig.real:无法 stat /usr/lib/libgfortran.so:没有这样的文件或目录
我已经删除并重新安装了 gfortran。我需要做什么来解决这个问题?
I'm trying to install the package lars. Ubuntu 11.04 Natty 64-bit. From building I get:
* installing *source* package âlarsâ ... ** libs gfortran -fpic -O3 -pipe -g -c delcol.f -o delcol.o gcc -shared -o lars.so delcol.o -lgfortran -lm -L/usr/lib64/R/lib -lR /usr/bin/ld: cannot find -lgfortran collect2: ld returned 1 exit status make: *** [lars.so] Error 1 ERROR: compilation failed for package âlarsâ
gfortran is installed and when I run gfortran --version
I get
gfortran --version GNU Fortran
(Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
sudo ldconfig -v
gives the error
/sbin/ldconfig.real: Cannot stat /usr/lib/libgfortran.so: No such file or directory
I have already removed and reinstalled gfortran. What do I need to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
我在尝试在 Ubuntu 12.10 64 位上安装 CRAN 软件包 VGAM 时遇到了同样的问题。我已经安装了 r-base-dev,但是 Andrew Redd 对 Dirk Eddelbuettel 的答案的第二条评论对我有用。
具体来说,我收到两个错误:
已通过以下行修复:
请注意,只需第一行即可解决原始帖子中的问题。第二行修复了 lquadmath 的额外错误。
I had the same problem when trying to install the CRAN package VGAM on Ubuntu 12.10 64bit. I already had r-base-dev installed, but Andrew Redd's second comment to Dirk Eddelbuettel's answer worked for me.
Specifically, I was getting two errors:
Which were fixed by the lines:
Note that only the first line would be necessary to take care of the problem from the original post. The second line fixed of my additional error with lquadmath.
对于 Debian / Ubuntu 系列,我们通常推荐
,因为它会提取编译时常用的所有软件包。这种方法一直受到测试,因为自动化包构建器依赖于此(以及附加的每个包构建依赖)。这里也列出了
gfortran
包;也许您之前的安装有一个损坏的链接,所以我也尝试 dpkg --purge gfortran; apt-get 安装 gfortran。也就是说,数十个 R 软件包(以及 R 本身)都使用 Fortran,因此这里不应该有任何魔法。For the Debian / Ubuntu family, we usually recommend
as it pulls in all packages commonly needed for compiling. And this approach gets tested all the time as the automated package builders rely on this (as well as additional per-package Build-Depends). The
gfortran
package is listed here too; maybe you have a broken link from a prior installation so I'd also trydpkg --purge gfortran; apt-get install gfortran
. That said, dozens of R packages (and R itself) use Fortran so there should not be any magic here.看起来其他建议已经解决了您的问题,但您的问题也适用于我,但解决方案在我的情况下有所不同。我的问题是我的 gcc 和 g++ 版本与我的 gfortran 版本不同。我使用以下命令来切换它们,使它们全部相同。
检查您拥有的 gcc、g++ 和 gfortran 版本:
<前><代码>g++ --版本
海湾合作委员会——版本
gfortran——版本
匹配它们,使它们全部相同:
在我的例子中,我只有一个版本的 gfortran,所以我只需更改 g++ 和 gcc 版本以匹配 gfortran 的版本。
It looks like other suggestions already fixed your problem, but your question also applied to me but the solution was different in my case. My problem was that my gcc and g++ versions differed from my gfortran version. I used the following to switch them so that they were all the same.
Check what version of gcc, g++, and gfortran you have:
Match them so that they are all the same:
In my case, I only had one version of gfortran so I simply changed the g++ and gcc versions to match that of gfortran.
我使用 Centos,但无法获取 r-base-dev。我还安装了gfortran,它的版本与gcc和g++匹配;它仍然不起作用。但是,我通过创建
~/.R/Makevars
解决了这个问题,使用我找到了安装 gfortran 的目录(显然问题是 R 找不到它),
它说我安装了 gfortran在 usr/bin/gfortran 中。
然后我向
.R/Makevars
添加了标志来告诉 R 使用:您可以这样编辑 Makevars 文件:
现在您已经进入了可以编辑文本文件的
vi
程序。输入i
进行编辑;您将在终端窗口底部看到INSERT
。然后你就可以输入我上面写的内容了。要保存更改并退出vi
,请按 esc 键,然后输入:wq
。我不完全确定 FLIBS 线是否正确,因为它对于 MacOS 来说非常不同。在 MacOS 中,gfortran 下有一个目录,其中包含要链接的库,但显然 gfortran 不是 linux 中的目录。至少这对我有用,也解决了
/usr/bin/ld: 找不到-lquadmath
的问题,所以我顺利安装了需要gfortran的R包。I use Centos and I can't get r-base-dev. I have also installed gfortran and its version matches that of gcc and g++; it still didn't work. However, I solved this problem by creating
~/.R/Makevars
, usingI found the directory where I installed gfortran (apparently the problem is that R can't find it) by
It said I installed gfortran in
usr/bin/gfortran
.Then I added flags to
.R/Makevars
to tell R to use:You can edit the Makevars file this way:
Now you have entered the
vi
program that can edit text files. Typei
to edit; you will seeINSERT
by the bottom of the terminal window. Then you can input what I put above. To save the changes and quitvi
, press the esc key, and type:wq
.I'm not totally sure if I put the FLIBS line correctly, since it's very different for MacOS. In MacOS, there's a directory under gfortran that has the libraries to link to, but apparently
gfortran
is not a directory in linux. At least this worked for me, and also solved the problem of/usr/bin/ld: cannot find -lquadmath
, so I installed R packages requiring gfortran smoothly.在 ubuntu 12.04、R3.1.0、x86 32 位上安装 R 包 minqa 时遇到同样的问题(实际上它是插入符号包安装的一部分)。
解决
由
sudo ln -s /usr/lib/i386-linux-gnu/libgfortran.so.3 /usr/lib/libgfortran.so
r-base-dev 重新安装不起作用,我没有由于所有依赖项,不要尝试重新安装 gfortran。
根据系统/版本,
ls -l /usr/lib/libgfortran.so
检查链接是否存在/正确。
Same problem installing R package minqa on ubuntu 12.04, R3.1.0., an x86 32bits (actually it was part of the caret package installation).
Solved by
sudo ln -s /usr/lib/i386-linux-gnu/libgfortran.so.3 /usr/lib/libgfortran.so
r-base-dev reinstall didn't work and I didn't try to re-install gfortran because of all the dependencies.
Depending on the system/version,
ls -l /usr/lib/libgfortran.so
checks that the link exists/is right.
对于在 Mac 上访问此页面并出现相同错误的任何人,请尝试以下操作:
安装 Homebrew 并运行:
然后,创建一个文件
~/.R/Makevars
,其内容如下(请注意,这对应于 gcc 版本 9.1.0):For anyone who reaches this page with the same error on a Mac, try the following:
Install Homebrew and run:
Then, create a file
~/.R/Makevars
with the contents (being mindful that this corresponded to gcc version 9.1.0):只是将其留在这里以供将来参考,就像我的情况(Amazon Linux EC2 AMI)一样,问题仅在于符号链接的命名,而不在于其位置。
Just leaving this here for future reference as in my case (Amazon Linux EC2 AMI) the issue was merely with the naming of the symbolic link and not with its location.
我不需要安装任何库。发布对我有用的内容,也许对某人有用。
我已将
~/.R/Makevars
定义为使用CC=gcc-8
。我的机器上默认的 gcc 是 7.4.0,但我安装了 gcc-8。
同时我没有gfortran 8,只有7.4.0。
注释掉 Makevars 中的行会使编译回退到使用默认的 gcc-7,然后成功使用 gfortran-7 lib。
I didn't have to install any libraries. Posting what worked for me, maybe it will be useful for someone.
I had
~/.R/Makevars
defining to useCC=gcc-8
.Default gcc on my machine is 7.4.0, but I installed gcc-8.
At the same time I didn't have gfortran 8, but only 7.4.0.
Commenting out the line in Makevars makes compilation fall back to use default gcc-7, and it was successfully using gfortran-7 lib then.
如果您使用 gcc44,您将需要:
If you are using gcc44, you'll need:
对于未来迷失的灵魂,它还有助于验证编译器版本是否全部匹配(根据 https://askubuntu.com/questions/ 276892/无法找到-lgfortran)。就我而言,gcc 和 gfortran 都是 4.8.4,但 g++ 是 4.6。
For future lost souls, it also helps to verify compiler versions all match (per https://askubuntu.com/questions/276892/cannot-find-lgfortran). In my case gcc and gfortran were both 4.8.4, but g++ was 4.6.
我从源代码编译了 GCC 7.4,但配置了
--enable-languages=c,c++
,它不安装需要的 Fortran。I compiled GCC 7.4 from source but configured
--enable-languages=c,c++
which doesn't install Fortran, which is needed.就我而言,调整 gcc、g++ 和 gfortran 版本是有效的。但是 update-alternatives --config 命令找不到替代方案,所以我必须先手动安装它们(在我的例子中,我必须将 g++ 和 gfortran 从版本 11 升级到 12)
:手动设置它们:
In my case, adjusting the gcc, g++ and gfortran versions worked. But the
update-alternatives --config
command couldn't find the alternatives so I had to manualy install them first (in my case I had to upgrade g++ and gfortran from version 11 to 12):and them manually set them:
作为威震天对 Mac 自制程序的回答的后续内容,我在依赖项方面也遇到了类似的问题:
只需在 bash 中输入
brew install openssl
即可在下一个 packages.install 上运行。As a follow-on to Megatron's answer for Mac homebrew, I had a similar problem with dependencies:
just typed
brew install openssl
into bash and it worked on next packages.install.