Score:2

Overcoming "undefined symbol: _gfortran_runtime_error_at" during R package, "glmnet" installation in WSL2 Focal

ma flag

I've been trying to install a R package, glmnet and having a installation issue. Here is an error output after I fired 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

I noticed two things; undefined symbol: _gfortran_runtime_error_at, which indicates the complier can't find libgfortan and clang++. I thought glmnet specifically requests gfortran as a compiler but for some reasons, clang is kicked in.

I have a Makevars setup in my ~/.R as follows;

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 

Paths to gfortran and its libraries are defined, and gfortran and libgfrotran are installed;

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

There is no alternative setup for gfortran;

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

I even added gfortran paths to a Makevars in the src directory of glmnet, and used R CMD INSTALL but got the same error.

I really appreciate any pointers to solve this issue.

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+/-.
hr flag
It looks like it's not even trying to link the library - have you tried `FLIBS=-L/usr/lib/gcc/x86_64-linux-gnu/9 -lgfortran -lm` ?
N0rbert avatar
zw flag
Can't reproduce on fresh 20.04 LTS docker container with either R 3.6 and R 4.1. Details needed. How did you installed R 4.1? Are you following guide from https://cran.r-project.org/bin/linux/ubuntu/ ? Why do you have `/home/rstudio` as home folder? Did you installed RStudio here? For reproducible result I would move or remove `/usr/local/lib/python3.8/dist-packages` out the way and retry R-package compilation.
akh22 avatar
ma flag
@steeldriver, I took your suggestion and it worked like a charm. For some reason, libgfortran path had to be explicitly indicated.
akh22 avatar
ma flag
@N0rbert, I did follow https://cran.r-project.org/bin/linux/ubuntu/fullREADME.html which has a simpler R install instruction. Rstudio installation automatically creates /home/rstudio by default. A Docker version of Focal is slightly different from WSL2 version of Focal. I don't if that makes any difference or not.
Score:2
ma flag

So I did modify FLIBS path in Makevars as suggested by steeldriver

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

and glmnet installed without a hitch. Interestingly, it still uses clang++ as a compiler but not 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)
hr flag
It possibly doesn't need a fortran *compiler* at all but still needs libgfortran (some BLAS routines may be implemented in fortran for example)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.