Install G77 on Ubuntu >=14.04

In 2012 I wrote how to install G77 on Ubuntu >=9.04. However that approach no longer works (yet that particular blog posts gets lots of hits because of a link from stackoverflow). So here are some updated instructions which work for Ubuntu >= 14.04.

First we need to add the Ubuntu 8.04 repo’s, do this by editing the sources.list file with your favourite text editor. I’ve used gedit here:

:~$ sudo gedit /etc/apt/sources.list

Then to the bottom of that file add:

deb http://old-releases.ubuntu.com/ubuntu/ hardy universe
deb-src http://old-releases.ubuntu.com/ubuntu/ hardy universe
deb http://old-releases.ubuntu.com/ubuntu/ hardy-updates universe
deb-src http://old-releases.ubuntu.com/ubuntu/ hardy-updates universe

Then we need to run an update and install g77, do this with:

:~$ sudo apt-get update
:~$ sudo apt-get install g77

You might get lucky and g77 might work for you straight away. Test it with a simple ‘Hello World!’ program. With a file name of something like `hello.f’ include the following lines:

>       program hello
>          print *, "Hello World!"
>       end program hello

and then in a terminal window, navigate to the folder containing hello.f and run:

:~$ g77 -o hello hello.f

Then (if nothing has gone wrong) be able to run the program `hello’ with:

:~$ ./hello

If you get error messages when compiling then there is probably a missing link. On Ubuntu 14.04 I got the error:

:~$ /usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status

This means ld can’t find a library (libgcc_s). You can help it, by finding the library yourself:

:~$ sudo find /usr/ -name libgcc_s.so

which returned a couple of versions for me, so I picked the latest one (which was located here: ‘/usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so’) and then checked where ld was expecting the library:

:~$ ld -lgcc_s --verbose

This returned loads of text, but the main bit we are interested in is right at the end:

==================================================
attempt to open /usr/x86_64-linux-gnu/lib64/libgcc_s.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libgcc_s.a failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libgcc_s.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libgcc_s.a failed
attempt to open //usr/local/lib64/libgcc_s.so failed
attempt to open //usr/local/lib64/libgcc_s.a failed
attempt to open //lib/x86_64-linux-gnu/libgcc_s.so failed
attempt to open //lib/x86_64-linux-gnu/libgcc_s.a failed
attempt to open //lib64/libgcc_s.so failed
attempt to open //lib64/libgcc_s.a failed
attempt to open //usr/lib/x86_64-linux-gnu/libgcc_s.so failed
attempt to open //usr/lib/x86_64-linux-gnu/libgcc_s.a failed
attempt to open //usr/lib64/libgcc_s.so failed
attempt to open //usr/lib64/libgcc_s.a failed
attempt to open //usr/local/lib/libgcc_s.so failed
attempt to open //usr/local/lib/libgcc_s.a failed
attempt to open //lib/libgcc_s.so failed
attempt to open //lib/libgcc_s.a failed
attempt to open //usr/lib/libgcc_s.so failed
attempt to open //usr/lib/libgcc_s.a failed
ld: cannot find -lgcc_s

If we make a symbolic link from where the actual file is to one of these locations then we’ll be all done:

:~$ sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so /usr/lib/x86_64-linux-gnu/

And now everything should work fine. Try compiling again to confirm. You’ll want to disable the old repo’s by adding `##’ in front of each one, i.e. reopen sources.list:

:~$ sudo gedit /etc/apt/sources.list

and change the last lines to:

## deb http://hu.archive.ubuntu.com/ubuntu/ hardy universe
## deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy universe
## deb http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe
## deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe

And do one more update:

:~$ sudo apt-get update

 

Other Errors:

 
If you get:

/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory

This is a bug which has been talked about before. The get around is to find where crti.o lives on your system:

:~$ sudo find /usr/ -name "crti.o"
/usr/lib32/crti.o
/usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o
/usr/lib/x86_64-linux-gnu/crti.o
/usr/libx32/crti.o

Take the location with “linux-gnu” in and add it to the environmental variable LIBRARY_PATH. To do this edit your .bashrc file and then reload it. Namely:

:~$ gedit ~/.bashrc

Then add to the end:

LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH
export LIBRARY_PATH

(replacing the path with the correct one for your system). Save and exit the file and then reload it:

:~$ source ~/.bashrc
This entry was posted in Linux and tagged , , . Bookmark the permalink.

2 Responses to Install G77 on Ubuntu >=14.04

  1. siti says:

    hi Dr

    i’m still new with g77. I just installed g77 and facing the error
    :~$ /usr/bin/ld: cannot find -lgcc_s
    collect2: ld returned 1 exit status

    i have tried to make a symbolic link as you suggested but still didn’t work. here is the libgcc_s in my computer

    /usr/lib/x86_64-linux-gnu/libgcc_s.so
    /usr/lib/libgcc_s.so
    /usr/lib/gcc/x86_64-linux-gnu/5/libgcc_s.so
    /usr/lib/gcc/x86_64-linux-gnu/3.4.6/32/libgcc_s.so
    /usr/lib/gcc/x86_64-linux-gnu/3.4.6/libgcc_s.so

    and where the ld was expecting the library :

    attempt to open //usr/local/lib/x86_64-linux-gnu/libgcc_s.so failed
    attempt to open //usr/local/lib/x86_64-linux-gnu/libgcc_s.a failed
    attempt to open //lib/x86_64-linux-gnu/libgcc_s.so failed
    attempt to open //lib/x86_64-linux-gnu/libgcc_s.a failed
    attempt to open //usr/lib/x86_64-linux-gnu/libgcc_s.so failed
    attempt to open //usr/lib/x86_64-linux-gnu/libgcc_s.a failed
    attempt to open //usr/local/lib64/libgcc_s.so failed
    attempt to open //usr/local/lib64/libgcc_s.a failed
    attempt to open //lib64/libgcc_s.so failed
    attempt to open //lib64/libgcc_s.a failed
    attempt to open //usr/lib64/libgcc_s.so failed
    attempt to open //usr/lib64/libgcc_s.a failed
    attempt to open //usr/local/lib/libgcc_s.so failed
    attempt to open //usr/local/lib/libgcc_s.a failed
    attempt to open //lib/libgcc_s.so failed
    attempt to open //lib/libgcc_s.a failed
    attempt to open //usr/lib/libgcc_s.so failed
    attempt to open //usr/lib/libgcc_s.a failed
    attempt to open //usr/x86_64-linux-gnu/lib64/libgcc_s.so failed
    attempt to open //usr/x86_64-linux-gnu/lib64/libgcc_s.a failed
    attempt to open //usr/x86_64-linux-gnu/lib/libgcc_s.so failed
    attempt to open //usr/x86_64-linux-gnu/lib/libgcc_s.a failed
    ld: cannot find -lgcc_s

    your kind advise or comments would be much appreciated.

    • Sean says:

      Hi,

      That is a strange problem since it seems like libgcc_s is in the right location. What command did you use to create the symbolic link? Also, what is the output of ‘ls -l /usr/lib/libgcc_s.so’ and ‘ls -l /usr/lib/x86_64-linux-gnu/libgcc_s.so’?

Leave a Reply

Your email address will not be published.