Search code examples
rrcpp

Recompile with -fPIC in R package


I'm attempting to install the imager package in R, but encountering the following error:

/usr/bin/ld: /usr/local/lib/libfftw3.a(assert.o): relocation R_X86_64_PC32 against symbol `stdout@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/share/make/shlib.mk:10: imager.so] Error 1
ERROR: compilation failed for package ‘imager’
* removing ‘/home/tjcooper/R/x86_64-pc-linux-gnu-library/4.0/imager’
Warning in install.packages :
  installation of package ‘imager’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpZagOIF/downloaded_packages’

i.e. some issue between shared and static libraries. I'm not entirely sure how to fix this - any ideas?

R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.1 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=en_IL.UTF-8       LC_NUMERIC=C               LC_TIME=en_IL.UTF-8        LC_COLLATE=en_IL.UTF-8     LC_MONETARY=en_IL.UTF-8    LC_MESSAGES=en_IL.UTF-8    LC_PAPER=en_IL.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_IL.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] SummarizedExperiment_1.20.0 Biobase_2.50.0              GenomicRanges_1.42.0        GenomeInfoDb_1.26.0         IRanges_2.24.0              S4Vectors_0.28.0           
[7] BiocGenerics_0.36.0         MatrixGenerics_1.2.0        matrixStats_0.57.0         

loaded via a namespace (and not attached):
  [1] bitops_1.0-6           GSVA_1.38.0            enrichplot_1.10.0      dynutils_1.0.5         bit64_4.0.5            RColorBrewer_1.1-2     httr_1.4.2             tools_4.0.3           
  [9] R6_2.5.0               irlba_2.3.3            DBI_1.1.0              colorspace_2.0-0       tidyselect_1.1.0       gridExtra_2.3          proxyC_0.1.5           bit_4.0.4             
 [17] compiler_4.0.3         graph_1.68.0           scatterpie_0.1.5       DelayedArray_0.16.0    shadowtext_0.0.7       scales_1.1.1           stringr_1.4.0          digest_0.6.27         
 [25] DOSE_3.16.0            XVector_0.30.0         pkgconfig_2.0.3        rlang_0.4.8            rstudioapi_0.13        RSQLite_2.2.1          farver_2.0.3           generics_0.1.0        
 [33] BiocParallel_1.24.1    GOSemSim_2.16.1        dplyr_1.0.2            RCurl_1.98-1.2         magrittr_1.5           GO.db_3.12.1           GenomeInfoDbData_1.2.4 Matrix_1.2-18         
 [41] Rcpp_1.0.5             dyndimred_1.0.3        munsell_0.5.0          viridis_0.5.1          lifecycle_0.2.0        stringi_1.5.3          ggraph_2.0.3           MASS_7.3-53           
 [49] zlibbioc_1.36.0        plyr_1.8.6             qvalue_2.22.0          grid_4.0.3             blob_1.2.1             ggrepel_0.8.2          DO.db_2.9              crayon_1.3.4          
 [57] lattice_0.20-41        cowplot_1.1.0          graphlayouts_0.7.1     splines_4.0.3          annotate_1.68.0        pillar_1.4.6           fgsea_1.16.0           igraph_1.2.6          
 [65] codetools_0.2-16       reshape2_1.4.4         fastmatch_1.1-0        XML_3.99-0.5           glue_1.4.2             downloader_0.4         BiocManager_1.30.10    data.table_1.13.2     
 [73] remotes_2.2.0          RcppParallel_5.0.2     foreach_1.5.1          tweenr_1.0.1           vctrs_0.3.4            polyclip_1.10-0        gtable_0.3.0           purrr_0.3.4           
 [81] tidyr_1.1.2            assertthat_0.2.1       ggplot2_3.3.2          ggforce_0.3.2          xfun_0.19              lmds_0.1.0             xtable_1.8-4           tidygraph_1.2.0       
 [89] viridisLite_0.3.0      tibble_3.0.4           pheatmap_1.0.12        iterators_1.0.13       rvcheck_0.1.8          clusterProfiler_3.18.0 tinytex_0.27           AnnotationDbi_1.52.0  
 [97] memoise_1.1.0          gam_1.20               ellipsis_0.3.1         GSEABase_1.52.0  

 

Solution

  • That usually means that the library you want to use, here libfftw3 was built the wrong way. The first preference is as a shared library creating libfftw3.so. thr second preference is a static library libftw3.a but with the -fPIC compile option for relocatable code. That is missing here, and exactly what the error message suggests.

    One my (Ubuntu) system it comes the right way:

    $ file /usr/lib/x86_64-linux-gnu/libfftw3.so
    /usr/lib/x86_64-linux-gnu/libfftw3.so: symbolic link to libfftw3.so.3.5.8
    $ file /usr/lib/x86_64-linux-gnu/libfftw3.so.3.5.8 
    /usr/lib/x86_64-linux-gnu/libfftw3.so.3.5.8: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=56a87c8c86308035675bfd1c10d09c29b5450bc7, stripped
    $ 
    

    You need to fix that and then try to reinstall imager.

    None of this has anything to do with Rcpp, by the way.

    Edit As you are also on Ubuntu, just do this:

    sudo apt install libfftw3-dev
    

    but also remove the installation below /usr/local as it would shadow the system installation. Then reinstall whatever uses fftw3 include imager.