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 (there is a problem with the GPG signature which is why we add ‘[trusted=yes]’):

deb [trusted=yes] http://old-releases.ubuntu.com/ubuntu/ hardy universe
deb-src [trusted=yes] http://old-releases.ubuntu.com/ubuntu/ hardy universe
deb [trusted=yes] http://old-releases.ubuntu.com/ubuntu/ hardy-updates universe
deb-src [trusted=yes] http://old-releases.ubuntu.com/ubuntu/ hardy-updates universe

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

:~$ sudo apt update
:~$ sudo apt 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 [trusted=yes] http://hu.archive.ubuntu.com/ubuntu/ hardy universe
## deb-src [trusted=yes] http://hu.archive.ubuntu.com/ubuntu/ hardy universe
## deb [trusted=yes] http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe
## deb-src [trusted=yes] http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe

And do one more update:

:~$ sudo apt 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.

6 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’?

  2. Jack says:

    Hi, I am very new to all of this so I am not sure why I am going wrong. When following you steps, I run into trouble with the “sudo apt-get install g77” command. The following text prints in the terminal when executing that command:

    The following packages have unmet dependencies:
    cpp-3.4:i386 : Depends: libc6:i386 (>= 2.7-1) but it is not going to be installed
    g77 : Depends: g77-3.4 (>= 3.4.6-1) but it is not going to be installed
    g77-3.4:i386 : Depends: libc6:i386 (>= 2.7-1) but it is not going to be installed
    gcc-3.4:i386 : Depends: binutils:i386 (>= 2.16.1-3) but it is not going to be installed
    Depends: libc6:i386 (>= 2.7-1) but it is not going to be installed
    Depends: libgcc1:i386 (>= 1:3.4.6-6ubuntu3) but it is not going to be installed
    Recommends: libc6-dev:i386 (>= 2.3.5-10) but it is not going to be installed
    libg2c0:i386 : Depends: libc6:i386 (>= 2.7-1) but it is not going to be installed
    E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).

    I don’t know what this means, let alone how to fix it. Any help is appreciated. Thanks!

  3. Jack says:

    Hello again. I created a new virtual machine so I could start from scratch, but now I am getting new errors after running through the entire process. The new errors are variations of:

    ./hello: In function `_fini’:
    (.fini+0x0): multiple definition of `_fini’
    /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_info): relocation 0 has invalid symbol index 7

    and
    ./hello: In function `data_start’:
    (.data+0x0): multiple definition of `__data_start’
    /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11

    followed by:
    /usr/lib/x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here
    ./hello: In function `data_start’:
    (.data+0x8): multiple definition of `__dso_handle’
    /usr/lib/gcc/x86_64-linux-gnu/3.4.6/crtbegin.o:(.data+0x0): first defined here
    ./hello:(.rodata+0x0): multiple definition of `_IO_stdin_used’
    /usr/lib/x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
    ./hello: In function `_start’:
    (.text+0x0): multiple definition of `_start’
    /usr/lib/x86_64-linux-gnu/crt1.o:/build/eglibc-ripdx6/eglibc-2.19/csu/../sysdeps/x86_64/start.S:118: first defined here
    ./hello: In function `_init’:
    (.init+0x0): multiple definition of `_init’
    /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_line): relocation 0 has invalid symbol index 4
    /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_line): relocation 1 has invalid symbol index 5
    /usr/lib/x86_64-linux-gnu/crti.o:/build/eglibc-ripdx6/eglibc-2.19/csu/../sysdeps/x86_64/crti.S:64: first defined here
    /usr/bin/ld: error in ./hello(.eh_frame); no .eh_frame_hdr table will be created.
    collect2: ld returned 1 exit status

    Thanks.

    • Sean says:

      These look like errors in your function ‘hello’ rather than with the installation of g77. At what stage of the installation did you get the error?

  4. Zakarya says:

    Hello Sir ,
    thank you so much for the precious informations about installing g77 on ubuntu
    i followed all the steps and i finally could install g77 and executed the program “hello”
    but when arrived to compile my program, i got this error
    /usr/bin/ld: cannot find -lnag
    collect2: ld a retourné 1 code d’état d’exécution
    make: *** [hvbk-coarse] Error 1
    i am waiting for your help , thank you in advance sir

Leave a Reply

Your email address will not be published.