According to "build g77 from source" in gfortran.org, we need to build one from older version of gcc: v3.4.6
Our environment is Ubuntu 9.04(jaunty), gcc 4.3.3
※ Install g77
Get "gcc-3.4.6.tar.gz" into a folder, and then key in
tar xvzf gcc-3.4.6.tar.gz
mkdir bin
mkdir run
cd bin
../gcc-3.4.6/configure --enable-languages=c,f77 --disable-checking --prefix=$HOME/g77/run
make CC=/usr/bin/gcc
make install
Then g77 compiler should be $HOME/g77/run/bin/g77
★ However, in this command:
make CC=/usr/bin/gcc
may encounter error message:
In function 「open」,
inlined from 「collect_execute」 at ../../gcc-3.4.6/gcc/collect2.c:1537:
/usr/include/bits/fcntl2.h:51: 錯誤: call to 「__open_missing_mode」 declared with attribute error: open with O_CREAT in second argument needs 3 arguments
make[1]: *** [collect2.o] Error 1
make[1]: Leaving directory `/home/cjclab/g77-3.4.6/bin/gcc'
make: *** [all-gcc] Error 2
solution is changing one line in $HOME/g77/gcc-3.4.6/gcc/collect2.c
from
redir_handle = open (redir.0_WRONLY | 0_TRUNC | 0_CREAT);)
to
redir_handle = open (redir.0_WRONLY | 0_TRUNC | 0_CREAT,0777);)
similar post ref here
※ using g77 to compile
When compiling with g77, you must add -static parameter to avoid link to libg2c0/libg2c.so.0. For example, compile test.f and turn into test.out:
$HOME/g77/run/bin/g77 -static test.f -o test.out
otherwise, you may encounter error message like this:
./test.out: error while loading shared libraries: libg2c.so.0: cannot open shared object file: No such file or directory
p.s. We were tring to compile CNS(Crystallographic/NMR Refinement Software), but actually in CNS version 1.21, binary installation is provided, so no need to compile by ourselves.