Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to install a package in R (package "ks"). It fails with error message:

/usr/bin/ld: cannot find -lgfortran

I've already installed the Ubuntu package build-essential:

sudo apt-get install build-essential

I've also tried adding symbolic links:

sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/
sudo ln -s /usr/lib/ /usr/lib/
sudo ldconfig

I use gcc and g++ regularly, but haven't yet had reason to use gfortran.

I've seen others with this problem on gcc-4.7 (, so I wonder if this is from manually installing gcc-4.7. I followed the recipe from the accepted answer here here and here here.

Running lsb_release -a prints

Ubuntu 12.04.2 LTS

and running uname -r prints


Can anyone offer advice for why ld doesn't work?

share|improve this question
You tried to make symbolic links against runtime libraries, not the ones that linker wants (*.a dev libs). Looks like the path issue. – Andrejs Cainikovs Apr 1 '13 at 20:55
up vote 2 down vote accepted

You need to install gfortran. The error points out that the static lib for build-time linking is missing not the dynamic libs you tried to adjust.

share|improve this answer
When I try sudo apt-get install gfortran, I get 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.... Any thoughts? – user Apr 1 '13 at 20:06
Well, on my system I get for dpkg -S /usr/lib/gcc/x86)64-linux-gnu/4.6/libgfortran.a the answer that this is from the gfortran-4.6 package. Gcc is looking for the .a file. If you installed another gcc version, the linker is looking inside a similarly named directory for libgfortran.a. – rfindeis Apr 1 '13 at 20:36
Looks like a valid answer. – Andrejs Cainikovs Apr 1 '13 at 20:59
Symbolic linking the 4.6 library for the 4.7 compiler might work. Also passing the correct path with -L (which is largely the same). If this fails you need to install the 4.7 version of gfortran from the ppa you used for gcc 4.7. What gfortran version do you have now? – rfindeis Apr 1 '13 at 21:00
I needed to use the same trick as installing gcc-4.7 to install gfortran-4.7. – user Apr 1 '13 at 23:43


cd /usr/lib/gcc/x86_64-linux-gnu/4.6
sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.a libgfortran.a
share|improve this answer
Could you make it a little more verbose? Maybe a separate cd line at least? – Volker Siegel Nov 22 '14 at 5:18
Please add an explanation. People should never blindly run commands they find on the internet. So please also don't write them. – the_Seppi Nov 23 '14 at 13:41

A little more explanation to @Cloud Oliver's answer.

Find out the gcc version currently being used through this command.

$sudo update-alternatives --config gcc

* 2            /usr/bin/gcc-4.7   60        manual mode

The entry with '*' tells which version of gcc is being used. Just press enter to keep the current settings.

  1. CD to the gcc directory:

    cd /usr/lib/gcc/x86_64-linux-gnu/4.7/
  2. You can search for libgfortran.a through the following command (Optional). In my case it was present in '/usr/lib/gcc/x86_64-linux-gnu/4.8/' directory.

    find /usr/lib/gcc/x86_64-linux-gnu/ -iname "libgfortran"
  3. Create the symlink:

    sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.a libgfortran.a
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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