18/5/14

Installing g77 compiler in ubuntu 10.04 & 11.10 & 12.04 (fortran77 compiler)

this posting is modified from http://aganse.blogspot.com/2012/05/installing-g77-on-ubuntu-1004-1110.html
However, g77 is no longer being maintained and was last made to support GCC 3.4. More recent Ubuntu versions use GCC 4.X and so dropped g77 from their default package manager lists. Took a little bit to figure out how to get the relevant stuff installed and working on these computers, as I still needed the GCC 4.X for other content on the machines. Here’s what I did:
The overall summary is, to get g77 and its libraries you have to temporarily modify an apt-get repository list file, install g77 (which automatically also installs its GCC 3.4 dependencies which won’t interfere with your gcc 4.x), and then set the repository file back to its original state. Also, there’s an additional little fix to install g77 in Ubuntu 11.10 that wasn’t in Ubuntu 10.04 (I haven’t tried the versions of Ubuntu in between): a few libs moved location, so you simply use an environment variable to tell g77 where they are. Steps detailed below:

sudo vi /etc/apt/sources.list
, then append the following lines to end of file

## temporarily adding these to install G77 which is no longer supported:
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

sudo apt-get update

sudo apt-get install g77 blcr-dkms: blcr-util: dkms: fakeroot: libcr0: libibverbs-dev: openmpi-common:
(Those entries with colons afterward prevent those packages from being removed to match the outdated setup, which we don’t wish to do)

sudo vi /etc/apt/sources.list
again and comment out those above lines at end of file.

sudo apt-get update
If you’re running Ubuntu 11.10 (but this is not needed for 10.04; I don’t know about versions in between, the error is about finding libs crt1.o, crti.o and lgcc_s):
Before running make (or g77 in general) you’ll need to enter the following line in your shell (note this is bash style here, mod as needed for other shells)


export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/usr/lib/gcc/x86_64-linux-gnu/4.6
(Note that is not the more common variable LD_LIBRARY_PATH…)
—————————–
this part is my modification because i’m using Ubuntu 12.04 32bit-i386, after installing g77, i have to change command above because there are some error message,


/usr/bin/ld: error: cannot open crt1.o: No such file or directory
/usr/bin/ld: error: cannot open crti.o: No such file or directory
/usr/bin/ld: error: cannot open crtn.o: No such file or directory
/usr/bin/ld: error: cannot open /usr/lib/gcc/i486-linux-gnu/3.4.6/libgcc_s.so: No such file or directory
/usr/bin/ld: error: cannot open /usr/lib/gcc/i486-linux-gnu/3.4.6/libgcc_s.so: No such file or directory
collect2: ld returned 1 exit status
so i have to find where are these lib file,

find /usr -name "crt1.o"
, and gotcha, these file location -> /usr/lib/i386-linux-gnu/
and like above solution:


sudo ln -s /usr/lib/i386-linux-gnu/crt*.o /usr/lib/gcc/i486-linux-gnu/

export LIBRARY_PATH=/usr/lib/gcc/i486-linux-gnu:/usr/lib/gcc/i686-linux-gnu/4.6
and my problem SOLVED by this method.. ckckck :D
——————————–

If you plan to do a lot of g77 compiles you might wish to add that LIBRARY_PATH line to your “~/.bashrc” file, but for just one or two compiles I personally choose not to do so.
Note that executables made with this g77 may rely by default on shared object libraries of g77/gcc 3.4, so if you copy your executable over to other modern Linux systems (say another 10.04 or 11.10 box — e.g. I use mine in a cluster), you may get a runtime error about shared object files. The solution is to install g77 on that other system as well by the same instructions above, so that the shared object files exist. It goes pretty quickly after the first time

Bài đăng phổ biến