解决 R 包期间出现“未定义符号:_gfortran_runtime_error_at”的问题,在 WSL2 Focal 中安装“glmnet”

解决 R 包期间出现“未定义符号:_gfortran_runtime_error_at”的问题,在 WSL2 Focal 中安装“glmnet”

我一直在尝试安装 R 包 glmnet,但遇到了安装问题。这是我触发后的错误输出install.packages("glmnet")

/usr/bin/clang++ -std=gnu++14 -shared -L/usr/lib/R/lib -L/usr/lib/llvm-13/lib -Wl,-rpath,/usr/lib/llvm-13/lib -o glmnet.so RcppExports.o elnet_exp.o glmnet5dpclean.o glmnet_init.o pb.o pb_exp.o wls.o wls_exp.o -L/usr/lib/gcc/x86_64-linux-gnu/9 -lm -L/usr/lib/R/lib -lR
installing to /home/rstudio/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-glmnet/00new/glmnet/libs
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘glmnet’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/rstudio/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-glmnet/00new/glmnet/libs/glmnet.so':
  /home/rstudio/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-glmnet/00new/glmnet/libs/glmnet.so: undefined symbol: _gfortran_runtime_error_at
Error: loading failed
Execution halted

我注意到两件事; undefined symbol: _gfortran_runtime_error_at,这表明编译器找不到 libgfortan 和 clang++。我以为 glmnet 专门请求 gfortran 作为编译器,但由于某些原因,clang 被启动了。

我的 ~/.R 中有一个 Makevars 设置,如下所示;

more .R/Makevars
C=/usr/bin/clang
#C89=/usr/bin/clang
#C99=/usr/bin/clang
CPP=/usr/bin/clang-cpp
CXX=/usr/bin/clang++
CXX11=/usr/bin/clang++
CXX14=/usr/bin/clang++
CXX17=/usr/bin/clang++
CXX1X=/usr/bin/clang++

SHLIB_OPENMP_CFLAGS = -fopenmp
CFLAGS=-g -O3 -Wall -pedantic -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -mtune=native -pipe
LDFLAGS=-L"/usr/lib/llvm-13/lib/clang/13.0.1/lib/linux" -Wl,-rpath,/usr/lib/llvm-13/lib/clang/13.0.1/lib/linux
CPPFLAGS= -I"/usr/lib/llvm-13/lib/clang/13.0.1/include"

FC=/usr/bin/gfortran
F77=/usr/bin/gfortran
FLIBS=-L/usr/lib/gcc/x86_64-linux-gnu/9 -lm
MAKEFLAGS  = -j12 

定义gfortran及其库的路径,并安装gfortran和libgfrotran;

gfortran --version
GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

locate libgfortran
    /usr/lib/gcc/x86_64-linux-gnu/9/libgfortran.a
    /usr/lib/gcc/x86_64-linux-gnu/9/libgfortran.so
    /usr/lib/gcc/x86_64-linux-gnu/9/libgfortran.spec
    /usr/lib/x86_64-linux-gnu/libgfortran.so.5
    /usr/lib/x86_64-linux-gnu/libgfortran.so.5.0.0
    /usr/local/lib/python3.8/dist-packages/numpy.libs/libgfortran-2e0d59d6.so.5.0.0
    /usr/local/lib/python3.8/dist-packages/scipy.libs/libgfortran-040039e1.so.5.0.0
    /usr/local/lib/python3.9/dist-packages/numpy.libs/libgfortran-2e0d59d6.so.5.0.0
    /usr/local/lib/python3.9/dist-packages/scipy.libs/libgfortran-040039e1.so.5.0.0
    /usr/share/doc/libgfortran-9-dev
    /usr/share/doc/libgfortran5

gfortran 没有替代设置;

sudo update-alternatives --config gfortran
update-alternatives: error: no alternatives for gfortran

我甚至将 gfortran 路径添加到 glmnet 的 src 目录中的 Makevars,并使用 R CMD INSTALL,但出现同样的错误。

我非常感谢任何能解决此问题的指点。

sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8    
 [5] LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C             
 [9] LC_ADDRESS=C           LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_3.3.5   phyloseq_1.39.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8             ape_5.6-2              lattice_0.20-45        prettyunits_1.1.1     
 [5] ps_1.6.0               Biostrings_2.62.0      rprojroot_2.0.2        assertthat_0.2.1      
 [9] foreach_1.5.2          utf8_1.2.2             R6_2.5.1               GenomeInfoDb_1.30.1   
[13] plyr_1.8.6             stats4_4.1.2           pillar_1.7.0           zlibbioc_1.40.0       
[17] rlang_1.0.1            curl_4.3.2             rstudioapi_0.13        data.table_1.14.3     
[21] callr_3.7.0            vegan_2.5-7            S4Vectors_0.32.3       Matrix_1.4-0          
[25] splines_4.1.2          stringr_1.4.0          igraph_1.2.11          RCurl_1.98-1.6        
[29] munsell_0.5.0          compiler_4.1.2         pkgconfig_2.0.3        BiocGenerics_0.40.0   
[33] pkgbuild_1.3.1         multtest_2.50.0        mgcv_1.8-39            biomformat_1.22.0     
[37] tidyselect_1.1.2       tibble_3.1.6           GenomeInfoDbData_1.2.7 IRanges_2.28.0        
[41] codetools_0.2-18       fansi_1.0.2            permute_0.9-7          crayon_1.5.0          
[45] dplyr_1.0.8            withr_2.4.3            MASS_7.3-55            bitops_1.0-7          
[49] rhdf5filters_1.6.0     grid_4.1.2             nlme_3.1-155           jsonlite_1.8.0        
[53] gtable_0.3.0           lifecycle_1.0.1        DBI_1.1.2              magrittr_2.0.2        
[57] scales_1.1.1           cli_3.2.0              stringi_1.7.6          XVector_0.34.0        
[61] reshape2_1.4.4         remotes_2.4.2          ellipsis_0.3.2         generics_0.1.2        
[65] vctrs_0.3.8            Rhdf5lib_1.16.0        iterators_1.0.14       tools_4.1.2           
[69] ade4_1.7-18            Biobase_2.54.0         glue_1.6.2             purrr_0.3.4           
[73] processx_3.5.2         parallel_4.1.2         survival_3.2-13        colorspace_2.0-3      
[77] rhdf5_2.38.0           BiocManager_1.30.16    cluster_2.1.2  

   
neofetch
            .-/+oossssoo+/-.               root@204152
        `:+ssssssssssssssssss+:`           ------------------
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 20.04.4 LTS on Windows 10 x86_64
    .ossssssssssssssssssdMMMNysssso.       Kernel: 5.4.72-microsoft-standard-WSL2
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Uptime: 11 days, 18 hours, 43 mins
  +ssssssssshmydMMMMMMMNddddyssssssss+     Packages: 1407 (dpkg)
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Shell: zsh 5.8
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Terminal: /dev/pts/2
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   CPU: Intel Xeon Gold 6230 (40) @ 2.094GHz
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   Memory: 1863MiB / 102724MiB
ossyNMMMNyMMhsssssssssssssshmmmhssssssso
+sssshhhyNMMNyssssssssssssyNMMMysssssss+
.ssssssssdMMMNhsssssssssshNMMMdssssssss.
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/
  +sssssssssdmydMMMMMMMMddddyssssssss+
   /ssssssssssshdmNNNNmyNMMMMhssssss/
    .ossssssssssssssssssdMMMNysssso.
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`
            .-/+oossssoo+/-.

答案1

因此我确实按照steeldriver的建议修改了Makevars中的FLIBS路径

FLIBS=-L/usr/lib/gcc/x86_64-linux-gnu/9 -lgfortran -lm

并且 glmnet 安装顺利。有趣的是,它仍然使用 clang++ 作为编译器,而不是 gfortran。

** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (glmnet)

相关内容