![R 4.0 库问题 lgfortran](https://linux22.com/image/936600/R%204.0%20%E5%BA%93%E9%97%AE%E9%A2%98%20lgfortran.png)
我正在尝试使用 R(r 版本 4.0)在我的计算机上安装一些库。我尝试运行以下命令:
install.packages("libcoin")
但它失败了,这里是很大一部分输出:
* installing *source* package ‘libcoin’ ...
** package ‘libcoin’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I'/home/fbenedet/R/x86_64-pc-linux-gnu-library/4.0/mvtnorm/include' -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c libcoin-init.c -o libcoin-init.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I'/home/fbenedet/R/x86_64-pc-linux-gnu-library/4.0/mvtnorm/include' -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c libcoin.c -o libcoin.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o libcoin.so libcoin-init.o libcoin.o -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
/usr/bin/ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/share/make/shlib.mk:10: libcoin.so] Error 1
ERROR: compilation failed for package ‘libcoin’
* removing ‘/home/fbenedet/R/x86_64-pc-linux-gnu-library/4.0/libcoin’
Warning in install.packages :
installation of package ‘libcoin’ had non-zero exit status
* installing *source* package ‘strucchange’ ...
** package ‘strucchange’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c strucchange_functions.c -o strucchange_functions.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c strucchange_init.c -o strucchange_init.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o strucchange.so strucchange_functions.o strucchange_init.o -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
/usr/bin/ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/share/make/shlib.mk:10: strucchange.so] Error 1
ERROR: compilation failed for package ‘strucchange’
* removing ‘/home/fbenedet/R/x86_64-pc-linux-gnu-library/4.0/strucchange’
Warning in install.packages :
installation of package ‘strucchange’ had non-zero exit status
ERROR: dependency ‘libcoin’ is not available for package ‘coin’
* removing ‘/home/fbenedet/R/x86_64-pc-linux-gnu-library/4.0/coin’
Warning in install.packages :
installation of package ‘coin’ had non-zero exit status
ERROR: dependencies ‘strucchange’, ‘coin’ are not available for package ‘party’
* removing ‘/home/fbenedet/R/x86_64-pc-linux-gnu-library/4.0/party’
Warning in install.packages :
installation of package ‘party’ had non-zero exit status
The downloaded source packages are in
‘/tmp/Rtmpr7uQ6y/downloaded_packages’
我立即想到它与 lgfortran 有问题,因为此消息表明:
/usr/bin/ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status
于是我开始寻找解决方案。我检查了一下是否有 r-base-dev
sudo apt install r-base-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
r-base-dev is already the newest version (4.0.3-1.1804.0).
我在我的系统中寻找 lgfortran 库:
apt list --installed | egrep 'libgfortran'
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libgfortran-10-dev/focal-updates,focal-security,now 10.2.0-5ubuntu1~20.04 amd64 [installed]
libgfortran-7-dev/focal,now 7.5.0-6ubuntu2 amd64 [installed]
libgfortran-9-dev/focal-updates,focal-security,now 9.3.0-17ubuntu1~20.04 amd64 [installed,automatic]
libgfortran4/focal,now 7.5.0-6ubuntu2 amd64 [installed,automatic]
libgfortran5/focal-updates,focal-security,now 10.2.0-5ubuntu1~20.04 amd64 [installed,automatic]
和
ldconfig -p | grep libgfortran
libgfortran.so.5 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgfortran.so.5
libgfortran.so.4 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgfortran.so.4
我现在很迷茫,不知道如何解决这个问题。有什么可以帮到我的吗?
答案1
向社区致歉...事实证明,如果您使用 gcc 替代版本,则可能无法在 R 中找到这些库。
我有这个:
sudo update-alternatives --config g++
There are 2 choices for the alternative g++ (providing /usr/bin/g++).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/g++-8 20 auto mode
1 /usr/bin/g++-8 20 manual mode
2 /usr/bin/g++-9 10 manual mode
和这个:
sudo update-alternatives --config gcc
There are 3 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-8 20 auto mode
1 /usr/bin/g++-9 10 manual mode
2 /usr/bin/gcc-8 20 manual mode
3 /usr/bin/gcc-9 10 manual mode
通过切换到 gcc 和 g++ 9,库的问题就消失了。我在发布问题后一分钟就发现了这一点。