简体   繁体   中英

/usr/bin/ld: cannot find -lgfortran when installing 'RcppArmadillo' in R

The primary goal is to use DiffBind (a R package) to analyze my ChIPseq data.

(I found another post which might be relevant to my issue, and tried to extract the solution from it, but I guess the content was too "advanced" for me... )

Following the suggestion that I might need to update my DiffBind I tried to install a new version of it.

By the checking the dependency of DiffBind I guess that the previous installation automatically install an old version of DiffBind because my R did not meet the requirement of current version of DiffBind.

But I was using the R under the root directory, for which I could not do much about it. So I decided install a newer version of R under my own directory. and I managed to do that.

Then I tried to install the current version of DiffBind, I got the error

ERROR: compilation failed for package ‘RcppArmadillo’

It turned out the dependency lib "RcppArmadillo" require a more up-to-date compiler, again, I was using the gcc compiler under the root directory, so I install a new version of gcc under my own directory.

    $ gcc --version

    gcc (GCC) 6.1.0

    Copyright (C) 2016 Free Software Foundation, Inc.

    This is free software; see the source for copying conditions.  There is NO

    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    $ which gcc

/$HOME/Programme/gcc-6.1.0/bin//gcc

After that I tried to install the DiffBind (RcppArmadillo) again, but met another error:

* installing *source* package ‘RcppArmadillo’ ...
**   package 'RcppArmadillo' successfully unpacked and MD5 sums checked 
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ accepts -g... (cached) yes
checking whether g++ version is sufficient... (6.1.0) yes
checking LAPACK_LIBS... fallback LAPACK from R 3.3.0 or later used
configure: creating ./config.status
config.status: creating inst/include/RcppArmadilloLapack.h
** libs
g++ -I/$HOME/Programme/R-3.3.1/lib64/R/include -DNDEBUG  -I//$HOME/Programme/zlib-1.2.11/include -I//$HOME/Programme/bzip2-1.0.6/include -I//$HOME/Programme/xz-5.2.3/include -I//$HOME/Programme/pcre-8.40/include -I//$HOME/Programme/curl-7.52.1/include -I"/$HOME/Programme/R-3.3.1/lib64/R/library/Rcpp/include"  -I../inst/include -fpic  -g -O2  -c RcppArmadillo.cpp -o RcppArmadillo.o
g++ -I/$HOME/Programme/R-3.3.1/lib64/R/include -DNDEBUG  -I//$HOME/Programme/zlib-1.2.11/include -I//$HOME/Programme/bzip2-1.0.6/include -I//$HOME/Programme/xz-5.2.3/include -I//$HOME/Programme/pcre-8.40/include -I//$HOME/Programme/curl-7.52.1/include -I"/$HOME/Programme/R-3.3.1/lib64/R/library/Rcpp/include"  -I../inst/include -fpic  -g -O2  -c RcppExports.cpp -o RcppExports.o
g++ -I/$HOME/Programme/R-3.3.1/lib64/R/include -DNDEBUG  -I//$HOME/Programme/zlib-1.2.11/include -I//$HOME/Programme/bzip2-1.0.6/include -I//$HOME/Programme/xz-5.2.3/include -I//$HOME/Programme/pcre-8.40/include -I//$HOME/Programme/curl-7.52.1/include -I"/$HOME/Programme/R-3.3.1/lib64/R/library/Rcpp/include"  -I../inst/include -fpic  -g -O2  -c fastLm.cpp -o fastLm.o
g++ -shared -L/$HOME/Programme/R-3.3.1/lib64/R/lib -L//$HOME/Programme/zlib-1.2.11/lib -L//$HOME/Programme/bzip2-1.0.6/lib -L//$HOME/Programme/xz-5.2.3/lib -L//$HOME/Programme/pcre-8.40/lib -L//$HOME/Programme/curl-7.52.1/lib -o RcppArmadillo.so RcppArmadillo.o RcppExports.o fastLm.o -L/$HOME/Programme/R-3.3.1/lib64/R/lib -lRlapack -L/$HOME/Programme/R-3.3.1/lib64/R/lib -lRblas -lgfortran -lm -L/$HOME/Programme/R-3.3.1/lib64/R/lib -lR
/usr/bin/ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status**

it turned out that gfortran could not be found. but when I checked existence of gfortran it exist:

$ which gfortran

/usr/bin/gfortran

$ gfortran --version 

GNU Fortran (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)

Copyright (C) 2010 Free Software Foundation, Inc.



GNU Fortran comes with NO WARRANTY, to the extent permitted by law.

You may redistribute copies of GNU Fortran

under the terms of the GNU General Public License.

For more information about these matters, see the file named COPYING

So I assumed that gcc could not find gfortran, which is under the root directory. how could I solve the problem? Or could it be possible that the mismatch between the gcc and gfortran is the problem? if that is the case, what could be done to circumvent it?

My R version:

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.7 (Santiago)

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

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

I think the issue mentioned here has been solved. As VladimirF mentioned in the comments, when I installed the new version of gcc, I did not enable the Fortran, which is not a default setting, so the gfortran was not installed in my previous attempts.

I deleted my previous Gcc, and re compiled it as follows:

tar -xvf gcc-6.1.0.tar.gz
cd gcc-6.1.0
./contrib/download_prerequisites 
mkdir build
cd build
../configure --prefix=$HOME/Programme/gcc-6.1.0 --enable-languages=c,c++,fortran --disable-multilib
make -j 8
make install

set path for new gcc and lib

it worked!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM