Linux – ld cannot find -lgfortran

arch linuxcmakelibrariesmake

I'm trying to compile Knut (a maths program) on Arch Linux with CMake and I'm getting the following error:

/usr/bin/ld: cannot find -lgfortran
/usr/bin/ld: cannot find -lquadmath
collect2: error: ld returned 1 exit status
make[2]: *** [cli/CMakeFiles/knut-cli.dir/build.make:101: cli/knut-cli] Error 1
make[1]: *** [CMakeFiles/Makefile2:498: cli/CMakeFiles/knut-cli.dir/all] Error 2
make: *** [Makefile:128: all] Error 2

I believe bothgfortran and quadmath are installed, and the links seem to be correct as well:

$ ls -al /usr/lib | grep "fortran"
lrwxrwxrwx   1 root root       20 Jun  3 23:11 libgfortran.so -> libgfortran.so.3.0.0
lrwxrwxrwx   1 root root       20 Jun  3 23:11 libgfortran.so.3 -> libgfortran.so.3.0.0
-rwxr-xr-x   1 root root  5858448 Jun  3 23:11 libgfortran.so.3.0.0
-rw-r--r--   1 root root      269 Jun  3 03:11 libgfortran.spec

$ ls -al /usr/lib | grep "libquadmath"
lrwxrwxrwx   1 root root       20 Jun  3 23:11 libquadmath.so -> libquadmath.so.0.0.0
lrwxrwxrwx   1 root root       20 Jun  3 23:11 libquadmath.so.0 -> libquadmath.so.0.0.0
-rwxr-xr-x   1 root root   958384 Jun  3 23:11 libquadmath.so.0.0.0

The same .so files are also found in /usr/lib64.

I have gfortran version 6.1.1. I don't know much CMake so the only thing I tried to change in the cmake command is to add -D CMAKE_PREFIX_PATH=/usr/lib, which didn't help.

Any suggestions how I could proceed to find the problem?

EDIT1

I've run cmake without the subsequent make and it seems all dependencies are met:

- The C compiler identification is GNU 6.1.1
-- The CXX compiler identification is GNU 6.1.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is GNU 6.1.1
-- Check for working Fortran compiler: /usr/bin/gfortran
-- Check for working Fortran compiler: /usr/bin/gfortran  -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/bin/gfortran supports Fortran 90
-- Checking whether /usr/bin/gfortran supports Fortran 90 -- yes
-- The shell is found: /usr/bin/sh
-- The C++ runtime library is /usr/lib/gcc/x86_64-pc-linux-  gnu/6.1.1/../../../../lib/libstdc++.a
-- The FORTRAN runtime library is libgfortran.a, /usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/libgcc.a and libquadmath.a
-- The DYNAMIC FORTRAN runtime library is /usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/../../../../lib/libgfortran.so
-- openBLAS was found as /usr/lib64/libopenblas.so.
-- Using system UMFPACK and AMD: /usr/lib64/libumfpack.so and /usr/lib64/libamd.so.
-- The includes are at /usr/include and /usr/include.
-- Using system LAPACK and ARPACK /usr/lib64/liblapack.so;/usr/lib64/libarpack.so.
-- The mxml library is /usr/lib64/libmxml.so.
-- The mxml include directory is /usr/include.
-- --> Qt5Core found.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mark/knut/knut/build

The aforementioned errors occur when I subsequently run make.

EDIT2

I've noticed that my /usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/ does not contain the static libraries libgfortran.a and libquadmath.a. I have gcc-4.8.5 on another computer and there these files exist. From the cmake output these are the two libraries that are not found it seems, since there is no path given for them.

Now I'm not sure what that means, whether that's a problem with my gfortran installation or something else?

EDIT3 June 24

The problem with libgfortran seems to be Arch specific. Apparently static libraries are usually not packaged in Arch. That's why the same gcc-fortran package in Debian contains files libgfortran.a and libquadmath.a but not in Arch. I've changed the options in PKGBUILD to options=('staticlibs') to include the static libraries for the next compilation (using abs). Then I copied the generated libgfortran.a and libquadmath.a files into /usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/ and the problem with libgfortran seems to be solved.

However, I'm getting now the Qt5 error mentioned by Knud Larsen.

Best Answer


https://github.com/rs1909/knut/tree/master/knut

/usr/bin/ld: cannot find -lgfortran

/usr/bin/ld: cannot find -lquadmath

Please read knut/knut/knut.spec.cmake → Buildrequires: libgfortran-static .... i.e. libgfortran.a

Probably the same for -lquadmath : libquadmath.a

( I get no errors with the cmake configuring : The Makefile is created.)


EDIT 1, 23 June : The above appears to be a configuring example only : The Makefile was created.

Build example(s) : PCLinuxOS 2016, CentOS 7, Fedora 24 are failing with Qt5 errors.

  • Debian 8 Jessie : No issues, except for a cmake generated syntax error in knut/knut/build/src/config.h . $ make and # make install are OK. The gfortran, g++ are version 4.9.2 . "libgfortran-4.9-dev" provides libgfortran.a, libquadmath.a

EDIT 2, June 23 : A build with Ubuntu 16.04 ... to try out a later compiler, gcc-5.3.1 ...

cd knut/knut/build/ && CC=gcc-5 CXX=g++-5 FC=gfortran-5 cmake .. && make && sudo make install
  • No issues ....

EDIT 3 : Testing knut with gcc/g++/gfortran version 6.1.1 → Debian 9 Stretch.

CC=gcc-6 CXX=g++-6 FC=gfortran-6 cmake .. && make ; # make install
  • Is also OK.

EDIT 4 : Build requirements .. # apt-get install g++ libopenblas-dev libqt5svg5-dev

The conclusion I can have from all the above is that the used Qt5 must fit. May be there's difference in the Qt5 configuration ? patching ? ... I don't find any important difference in the Qt5 file locations.

Related Question