构建 R 包并出现错误“ld: 找不到 -lgfortran”

发布于 2024-11-14 22:53:07 字数 707 浏览 2 评论 0原文

我正在尝试安装 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

帅哥哥的热头脑 2024-11-21 22:53:07

我在尝试在 Ubuntu 12.10 64 位上安装 CRAN 软件包 VGAM 时遇到了同样的问题。我已经安装了 r-base-dev,但是 Andrew Redd 对 Dirk Eddelbuettel 的答案的第二条评论对我有用。

具体来说,我收到两个错误:

/usr/bin/ld: cannot find -lgfortran
/usr/bin/ld: cannot find -lquadmath

已通过以下行修复:

sudo ln -s /usr/lib/x86_64-linux-gnu/libgfortran.so.3 /usr/lib/libgfortran.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libquadmath.so.0 /usr/lib/libquadmath.so

请注意,只需第一行即可解决原始帖子中的问题。第二行修复了 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:

/usr/bin/ld: cannot find -lgfortran
/usr/bin/ld: cannot find -lquadmath

Which were fixed by the lines:

sudo ln -s /usr/lib/x86_64-linux-gnu/libgfortran.so.3 /usr/lib/libgfortran.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libquadmath.so.0 /usr/lib/libquadmath.so

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.

叹沉浮 2024-11-21 22:53:07

对于 Debian / Ubuntu 系列,我们通常推荐

 $ sudo apt-get install r-base-dev

,因为它会提取编译时常用的所有软件包。这种方法一直受到测试,因为自动化包构建器依赖于此(以及附加的每个包构建依赖)。这里也列出了 gfortran 包;也许您之前的安装有一个损坏的链接,所以我也尝试 dpkg --purge gfortran; apt-get 安装 gfortran。也就是说,数十个 R 软件包(以及 R 本身)都使用 Fortran,因此这里不应该有任何魔法。

For the Debian / Ubuntu family, we usually recommend

 $ sudo apt-get install r-base-dev

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 try dpkg --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.

江心雾 2024-11-21 22:53:07

看起来其他建议已经解决了您的问题,但您的问题也适用于我,但解决方案在我的情况下有所不同。我的问题是我的 gcc 和 g++ 版本与我的 gfortran 版本不同。我使用以下命令来切换它们,使它们全部相同。

  1. 检查您拥有的 gcc、g++ 和 gfortran 版本:

    <前><代码>g++ --版本
    海湾合作委员会——版本
    gfortran——版本

  2. 匹配它们,使它们全部相同:

    sudo update-alternatives --config g++
    sudo update-alternatives --config gcc
    sudo update-alternatives --config 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.

  1. Check what version of gcc, g++, and gfortran you have:

    g++ --version
    gcc --version
    gfortran --version
    
  2. Match them so that they are all the same:

    sudo update-alternatives --config g++
    sudo update-alternatives --config gcc
    sudo update-alternatives --config gfortran
    

In my case, I only had one version of gfortran so I simply changed the g++ and gcc versions to match that of gfortran.

记忆之渊 2024-11-21 22:53:07

我使用 Centos,但无法获取 r-base-dev。我还安装了gfortran,它的版本与gcc和g++匹配;它仍然不起作用。但是,我通过创建 ~/.R/Makevars 解决了这个问题,使用

cd ~
mkdir .R
touch Makevars

我找到了安装 gfortran 的目录(显然问题是 R 找不到它),

which gfortran

它说我安装了 gfortran在 usr/bin/gfortran 中。
然后我向 .R/Makevars 添加了标志来告诉 R 使用:

F77 = /usr/bin/gfortran
FC = $F77
FLIBS = -L/usr/bin/gfortran

您可以这样编辑 Makevars 文件:

vi .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, using

cd ~
mkdir .R
touch Makevars

I found the directory where I installed gfortran (apparently the problem is that R can't find it) by

which gfortran

It said I installed gfortran in usr/bin/gfortran.
Then I added flags to .R/Makevars to tell R to use:

F77 = /usr/bin/gfortran
FC = $F77
FLIBS = -L/usr/bin/gfortran

You can edit the Makevars file this way:

vi .R/Makevars

Now you have entered the vi program that can edit text files. Type i to edit; you will see INSERT by the bottom of the terminal window. Then you can input what I put above. To save the changes and quit vi, 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.

腹黑女流氓 2024-11-21 22:53:07

在 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.

各自安好 2024-11-21 22:53:07

对于在 Mac 上访问此页面并出现相同错误的任何人,请尝试以下操作:

安装 Homebrew 并运行:

brew install gcc

然后,创建一个文件 ~/.R/Makevars ,其内容如下(请注意,这对应于 gcc 版本 9.1.0):

VER=-9
CC=gcc$(VER)
CXX=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc/9.1.0/lib/gcc/9

  • R v3。 6.0
  • 海湾合作委员会v9.1.0
  • Homebrew v2.1.6
  • macOS v10.14.5

For anyone who reaches this page with the same error on a Mac, try the following:

Install Homebrew and run:

brew install gcc

Then, create a file ~/.R/Makevars with the contents (being mindful that this corresponded to gcc version 9.1.0):

VER=-9
CC=gcc$(VER)
CXX=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc/9.1.0/lib/gcc/9

  • R v3.6.0
  • gcc v9.1.0
  • Homebrew v2.1.6
  • macOS v10.14.5
柏拉图鍀咏恒 2024-11-21 22:53:07

只是将其留在这里以供将来参考,就像我的情况(Amazon Linux EC2 AMI)一样,问题仅在于符号链接的命名,而不在于其位置。

sudo ln -s /usr/lib64/libgfortran.so.3 /usr/lib64/libgfortran.so
sudo ln -s /usr/lib64/libquadmath.so.0 /usr/lib64/libquadmath.so

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.

sudo ln -s /usr/lib64/libgfortran.so.3 /usr/lib64/libgfortran.so
sudo ln -s /usr/lib64/libquadmath.so.0 /usr/lib64/libquadmath.so
韶华倾负 2024-11-21 22:53:07

我不需要安装任何库。发布对我有用的内容,也许对某人有用。

我已将 ~/.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 use CC=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.

落花浅忆 2024-11-21 22:53:07

如果您使用 gcc44,您将需要:

yum install gcc44-gfortran

If you are using gcc44, you'll need:

yum install gcc44-gfortran
染火枫林 2024-11-21 22:53:07

对于未来迷失的灵魂,它还有助于验证编译器版本是否全部匹配(根据 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.

平生欢 2024-11-21 22:53:07

我从源代码编译了 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.

苦妄 2024-11-21 22:53:07

就我而言,调整 gcc、g++ 和 gfortran 版本是有效的。但是 update-alternatives --config 命令找不到替代方案,所以我必须先手动安装它们(在我的例子中,我必须将 g++ 和 gfortran 从版本 11 升级到 12)

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100
sudo update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-12 100

:手动设置它们:

sudo update-alternatives --set g++ /usr/bin/g++-12
sudo update-alternatives --set gfortran /usr/bin/gfortran-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):

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100
sudo update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-12 100

and them manually set them:

sudo update-alternatives --set g++ /usr/bin/g++-12
sudo update-alternatives --set gfortran /usr/bin/gfortran-12
自由如风 2024-11-21 22:53:07

作为威震天对 Mac 自制程序的回答的后续内容,我在依赖项方面也遇到了类似的问题:

错误:包“openssl”配置失败
删除“/usr/local/lib/R/4.1/site-library/openssl”
install.packages 中的警告:
包“openssl”的安装具有非零退出状态

只需在 bash 中输入 brew install openssl 即可在下一个 packages.install 上运行。

As a follow-on to Megatron's answer for Mac homebrew, I had a similar problem with dependencies:

ERROR: configuration failed for package ‘openssl’
removing ‘/usr/local/lib/R/4.1/site-library/openssl’
Warning in install.packages :
installation of package ‘openssl’ had non-zero exit status

just typed brew install openssl into bash and it worked on next packages.install.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文