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?


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.


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.

  • Did you run cmake, then install gfortran? If so, you need to rerun cmake (remove its CMakeCache.txt first).
    – Kusalananda
    Jun 16, 2016 at 18:27
  • I had gfortran before running cmake but I also clean the build directory after every try. Jun 16, 2016 at 18:37

1 Answer 1



/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.

  • Would you mind sharing your distro and gcc/fortran version? Jun 17, 2016 at 11:05
  • »» Would you mind sharing .. «« : Yes, when I find the OS ... I used that day. I.e. I have all the mainstream OS´s / all versions. ( Currently no Arch Linux.) Jun 22, 2016 at 21:56
  • OK, I gave up trying to fix the qt5 error in Arch. But even in Ubuntu 16.04, with gcc-5.3.1, I'm getting the qt5 error. qtbase5-dev should be enough right? Or did you use any different qt5 package? Many thanks by the way! Jun 24, 2016 at 14:50
  • Debian Stretch, Ubuntu 16.04 : # apt-get install libqt5svg5-dev ... will do for all the Qt5 . See the edited post : Build requirements. Jun 25, 2016 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.