2

I have installed (GCC) 4.7.2 20121015 (Red Hat 4.7.2-5) already and jave also installed yum install gcc-gfortran . (Package gcc-gfortran-4.4.7-18.el6.x86_64)

But I'm getting error like :

/usr/bin/ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status
make: *** [quadprog.so] Error 1

Please help me in installing -lgfortran. It seems like I need to install "Fortran -dev package providing the Fortran library". I do not know how to do that in RedHat/CentOS. Please help. I'm facing hard time in doing this.

I have tried installing libgfortran using:

yum install libgfortran

But it says:

Package libgfortran-4.4.7-18.el6.x86_64 already installed and latest version Nothing to do (Running in an interactive session, skipping clean step.)

More Info: I tried installing package quadprog for R and below are the logs:

install.packages('https://cran.cnr.berkeley.edu/src/contrib/quadprog_1.5-5.tar.gz',dependencies = TRUE,repos = NULL,type ="source")
Installing package into '/usr/lib64/R/library'
(as 'lib' is unspecified)
trying URL 'https://cran.cnr.berkeley.edu/src/contrib/quadprog_1.5-5.tar.gz'
Content type 'application/x-gzip' length 33651 bytes (32 KB)
==================================================
downloaded 32 KB

* installing *source* package 'quadprog' ...
** package 'quadprog' successfully unpacked and MD5 sums checked
** libs
gfortran -m64  -fvisibility=hidden -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/lib64/gfortran/modules  -c aind.f -o aind.o
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG   -I/usr/local/include   -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fpic -fPIC   -c init.c -o init.o
gfortran -m64 -fvisibility=hidden -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/lib64/gfortran/modules -ffloat-store   -c -o solve.QP.compact.o solve.QP.compact.f
solve.QP.compact.f:254.3:

 72   if (nvl .EQ. 0) then                                              
   1
Warning: Label 72 at (1) defined but not used
solve.QP.compact.f:302.2:

 7       t1inf = .FALSE.                                                
  1
Warning: Label 7 at (1) defined but not used
solve.QP.compact.f: In function 'qpgen1':
solve.QP.compact.f:94: warning: 'it1' may be used uninitialized in this function
solve.QP.compact.f:98: warning: 't1' may be used uninitialized in this function
gfortran -m64 -fvisibility=hidden -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/lib64/gfortran/modules -ffloat-store   -c -o solve.QP.o solve.QP.f
solve.QP.f:245.3:

 72   if (nvl .EQ. 0) then                                              
   1
Warning: Label 72 at (1) defined but not used
solve.QP.f:293.2:

 7       t1inf = .FALSE.                                                
  1
Warning: Label 7 at (1) defined but not used
solve.QP.f: In function 'qpgen2':
solve.QP.f:85: warning: 'it1' may be used uninitialized in this function
solve.QP.f:89: warning: 't1' may be used uninitialized in this function
gfortran -m64  -fvisibility=hidden -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/lib64/gfortran/modules  -c util.f -o util.o
gcc -m64 -std=gnu99 -shared -L/usr/lib64/R/lib -o quadprog.so aind.o init.o solve.QP.compact.o solve.QP.o util.o -L/usr/lib64/R/lib -lRblas -lgfortran -lm -lgfortran -lm -L/usr/lib64/R/lib -lR
/usr/bin/ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status
make: *** [quadprog.so] Error 1
ERROR: compilation failed for package 'quadprog'
* removing '/usr/lib64/R/library/quadprog'
Warning message:
In install.packages("https://cran.cnr.berkeley.edu/src/contrib/quadprog_1.5-5.tar.gz",  :
  installation of package '/tmp/Rtmpry5XTG/downloaded_packages/quadprog_1.5-5.tar.gz' had non-zero exit status

Edits :

bash-4.1# rpm -ql libgfortran
/usr/lib64/libgfortran.so.3
/usr/lib64/libgfortran.so.3.0.0
Ashag
  • 837
  • 2
  • 15
  • 24

2 Answers2

1

You showed us this:

# type -a gcc

 gcc is /opt/centos/devtoolset-1.1/root/usr/bin/gcc 
 gcc is /usr/bin/gcc'

It means that you have installed Red Hat Developer Toolset and enabled it for this shell, using scl enable or a similar command. Do you still need it? If not, I suggest to disable it.

If you need DTS, you will have to install the Fortran compiler from DTS 1.1, using:

yum install devtoolset-1.1-gcc-gfortran

(Or download it directly from here, which seems to be the repository from where you got your DTS compiler.)

This will install the Fortran compiler which is compatible with the gcc compiler you have configured. Without that, the system Fortran compiler and the DTS gcc are used together, which does not work because the DTS gcc command (used for linking in the build process you quoted) is not able to locate the libgfortran.so library from the system Fortran compiler.

Alternatively, you can bring the two compilers into sync by deinstalling the DTS compiler:

yum install devtoolset-1.1-gcc-gfortran
Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • I don't think I need this. May be while trying to fix this, i have installed it. I will disable it. So what is the solution exactly? – Ashag Jul 25 '17 at 06:42
  • Disable DTS, or install `devtoolset-1.1-gcc-gfortran`. Either approach should fix your problem. – Florian Weimer Jul 25 '17 at 06:43
  • alright. I'm doing this. Will add a comment ; to let you know if it works or not – Ashag Jul 25 '17 at 06:44
  • Please answer this; before doing yum install devtoolset-1.1-gcc-gfortran ; i need to disable something? If yes how do i disable? or else i should do yum install devtoolset-1.1-gcc-gfortran directly? – Ashag Jul 25 '17 at 06:59
  • You can install the package directly. – Florian Weimer Jul 25 '17 at 07:01
  • Ok so when i did this ; it gave me this : No package devtoolset-1.1-gcc-gfortran available. Error: Nothing to do – Ashag Jul 25 '17 at 07:02
  • Then you should try to disable DTS instead. Depending on how you have set it up, just logging in again may be enough to do this. – Florian Weimer Jul 25 '17 at 07:03
  • how to disable? I didnot do enable anytime – Ashag Jul 25 '17 at 07:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/150052/discussion-between-florian-weimer-and-ashag). – Florian Weimer Jul 25 '17 at 07:05
  • I don't know which is accurate answer. But I have upvoted your answer. Both solution's worked for me. Thanks very much. – Ashag Jul 25 '17 at 08:23
  • If you want you can also post your answer https://stackoverflow.com/questions/45292188/cannot-install-r-tseries-quadprog-xts-packages-in-linux . I will upvote it. that's where the problem started. – Ashag Jul 25 '17 at 08:24
0

The following compile line was looking for libgfortran at /usr/lib64/R/lib but the library is not there. Hence, the linker error.

gcc -m64 -std=gnu99 -shared -L/usr/lib64/R/lib -o quadprog.so aind.o init.o solve.QP.compact.o solve.QP.o util.o -L/usr/lib64/R/lib -lRblas -lgfortran -lm -lgfortran -lm -L/usr/lib64/R/lib -lR

As we could not locate and modify the makefile. We created a symbolic link /usr/lib64/R/lib/libgfortran.so to /usr/lib64/libgfortran.so.3 and rerun the installation steps and it resolves the linker error.

This is a work around that we follow which resolves the issue

dlmeetei
  • 9,905
  • 3
  • 31
  • 38
  • I do not know how to edit this makefile. Please guide. – Ashag Jul 25 '17 at 06:01
  • `/usr/lib64` is on the default linker search path for this distribution, so it will not make a difference. – Florian Weimer Jul 25 '17 at 06:06
  • @dlmeetei Someone suggested "So you have the Fortran compiler. You still need the Fortran -dev package providing the Fortran library you failed to link against. I do not know what RedHat/CentOS call that -- under Debian it would be libgfortran-6-dev for gcc-6 etc pp." If this makes any sense to you then please help – Ashag Jul 25 '17 at 06:11
  • Downvoter, please explain the reason for downvoting? So that I can change, His issue is not passing the proper location to `libgfortran` – dlmeetei Jul 25 '17 at 06:13
  • @Ashag, share you makefile in your question so that we can point where to modify – dlmeetei Jul 25 '17 at 06:14
  • Which make file you want out of this? – Ashag Jul 25 '17 at 06:17
  • I am sorry I can not help, you don't know which makefile you are using – dlmeetei Jul 25 '17 at 06:18
  • If you can tell where i can find which makefile you are interested in and how to find. I can tell you. I am new to all this. i started with R and ended up in this issue. – Ashag Jul 25 '17 at 06:20
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/150049/discussion-between-dlmeetei-and-ashag). – dlmeetei Jul 25 '17 at 06:45
  • I don't know which is accurate answer. But I have upvoted your answer. Both solution's worked for me. Thanks very much. – Ashag Jul 25 '17 at 08:23
  • If you want you can also post your answer https://stackoverflow.com/questions/45292188/cannot-install-r-tseries-quadprog-xts-packages-in-linux . I will upvote it. that's where the problem started. – Ashag Jul 25 '17 at 08:24