Linux

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

13 thoughts on “Install G77 on Ubuntu >=14.04

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

    1. 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. I had the same problem with you , but when I use ‘4.8’ rather than ‘3.4.6’ version in
      ‘sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so /usr/lib/x86_64-linux-gnu/

      then it works.

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

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

  5. g77 last appeared as part of gcc 3.4.6 (as part of an Ubuntu debian package) as far as I can tell, with a changelog dated 2006-03-06 which is over 13 years ago.

    Is it really a good idea to be installing binaries and libraries created with tools on machines from 13 years ago?

    Now since g77 was not in fact a compiler but a front end to gcc, why not just use a fortran frontend from a currently maintained version of gcc?

    If one absolutely needs a g77 executable (for example in building silc), a shell script containing the command should be more than adequate

    /usr/bin/gfortran-5 -std=”f95″ “${@}”

    Yes it is fortran95 standard, but that is oldest that current gcc supports, but
    as the manual page explains

    “warnings are given for the Fortran 77 features that are permitted but
    obsolescent in later standards.”

    Personally I can live with warnings rather than the contents of ancient packages which may contain long since resolved buffer overflows or other security holes.

    If you are trying to compile Fortran 77 code which contains features not even permitted in Fortran 95, maybe it is better to update the code written to a 42 year old standard rather than the more sprightly 24 year old standard?

    Alternatively just grab the source code for gcc 3.4.6 and compile that anew to be safer than ancient binary package installs …

  6. for the g77 “simulator” shell script, the following is in fact necessary to get around ancient deprecated no longer permitted declarations such as INTEGER*4, and because the library libg2c no longer exists and does not need to be linked it needs be removed from the parameters if present …

    #! /bin/sh

    parameters=$(echo -n “${@}” | sed -e s’| -lg2c||’)

    echo “/usr/bin/gfortran-5 -pedantic -Wall ${parameters}”

    /usr/bin/gfortran-5 -std=”f95″ -pedantic -Wall ${parameters}
    status=${?}

    exit ${status}

    The echo line is there to avoid any “deception by hiding” when it is being used from a Makefile calling g77

  7. I have the same problem knowing that I use ‘3.4.6’ version; this error appears:

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

    I followed the steps you described but after typing:

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

    this error appears:

    ln: failed to create symbolic link ‘/usr/lib/x86_64-linux-gnu/libgcc_s.so’: File exists

    How can I solve this problem?

  8. Hello
    I have the same problem knowing that I use ‘3.4.6’ version; this error appears:

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

    I followed the steps you described but after typing:

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

    this error appears:

    ln: failed to create symbolic link ‘/usr/lib/x86_64-linux-gnu/libgcc_s.so’: File exists

    How can I solve this problem?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.