0

I am trying to run some of old legacy fortran code of my team.

  1. I have two Fortran 77 codes (cklib.f and grcom.f) which I compile using fort77 and got two object files.
  2. And I have two Fortran 90 codes (write_counterflow_sol.f and read_counterflow_sol.f) which I compile using gfortran and got another two object files.

Now, using a following makefile, I am trying to create an executable called remail.e

SOURCE_CHEMKIN = ../CHEMKIN/DATA_BASES/SOURCES
SOURCE_APPLI= ../SOURCES_COUNTERFLOW/
SOURCES_f77 = $(SOURCE_CHEMKIN)cklib.f $(SOURCE_APPLI)grcom.f $(SOURCE_APPLI)write_counterflow_sol.f $(SOURCE_APPLI)read_counterflow_sol.f
TARGET = remail.e
OBJECTS =  $(SOURCES_f77:.f=.o)
COMPILE = f90
.f90.o :
    $(COMPILE) -o $*.o -c $*.f90
.f.o :
    $(COMPILE) -o $*.o -c $*.f
$(TARGET) : $(OBJECTS)
$(COMPILE)  $(OBJECTS) -o $@
del :
$(DELETE) $(OBJECTS)

but end up with the following error,

make: f90: Command not found
make: *** [remail.e] Error 127

I know there is no f90 compiler in my system, so I tried with COMPILE=gfortran instead of COMPILE=f90in the makefile and ended up with this error.

gfortran  ../CHEMKIN/DATA_BASES/SOURCES/cklib.o ../SOURCES_COUNTERFLOW/grcom.o ../SOURCES_COUNTERFLOW/write_counterflow_sol.o ../SOURCES_COUNTERFLOW/read_counterflow_sol.o -o remail.e
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2 
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start': 
(.text+0x20): undefined reference to `main'
../CHEMKIN/DATA_BASES/SOURCES/cklib.o: In function `ckcomp_':
fort77-27216-1.c:(.text+0x3a4a): undefined reference to `s_cmp'
../CHEMKIN/DATA_BASES/SOURCES/cklib.o: In function `ckcpml_':
fort77-27216-1.c:(.text+0x3eb8): undefined reference to `pow_di'
fort77-27216-1.c:(.text+0x476f): undefined reference to `s_wsle'
fort77-27216-1.c:(.text+0x4788): undefined reference to `do_lio'
fort77-27216-1.c:(.text+0x478d): undefined reference to `e_wsle'
../CHEMKIN/DATA_BASES/SOURCES/cklib.o: In function `ckrat_':
fort77-27216-1.c:(.text+0xfac0): undefined reference to `pow_dd'
fort77-27216-1.c:(.text+0xfb17): undefined reference to `pow_dd'
fort77-27216-1.c:(.text+0xfef5): undefined reference to `pow_di'
../SOURCES_COUNTERFLOW/grcom.o: In function `MAIN__':
fort77-27073-1.c:(.text+0x1d): undefined reference to `s_copy'
fort77-27073-1.c:(.text+0x36): undefined reference to `s_copy'
fort77-27073-1.c:(.text+0x13e): undefined reference to `s_wsle' 
../SOURCES_COUNTERFLOW/write_counterflow_sol.o: In function `write_counterflow_sol__':
fort77-27083-1.c:(.text+0x85): undefined reference to `f_open'
fort77-27083-1.c:(.text+0xc0): undefined reference to `s_wsfe'
fort77-27083-1.c:(.text+0xd6): undefined reference to `do_fio'
../SOURCES_COUNTERFLOW/read_counterflow_sol.o: In function `read_counterflow_sol__':
fort77-28808-1.c:(.text+0x85): undefined reference to `f_open'
fort77-28808-1.c:(.text+0x9b): undefined reference to `s_rsfe'
fort77-28808-1.c:(.text+0xb1): undefined reference to `do_fio'
collect2: error: ld returned 1 exit status
make: *** [remail.e] Error 1

Also I tried with COMPILE=f77 in the makefile and successfully executed but when I run the executable I get this following error.

fmt: end of file
apparent state: unit 14 named sol2
last format: (3i10)
lately reading sequential formatted external IO
Aborted (core dumped)

The output of f77 -v gives the following,

/usr/bin/f77: fort77 Version 1.15
/usr/bin/f77: No input files specified

The output of f77 --version gives the following,

/usr/bin/f77: Illegal option: --version

The output of type f77 gives the following,

f77 is hashed (/usr/bin/f77)

Sorry for the long post. But any help is appreciated.

  • 2
    The `f77` is very likely the very same `gfortran`that you can also call by calling `gfortran`. What does `f77 -v` or `f77 --version` print? – Vladimir F Героям слава Jan 07 '22 at 10:12
  • See https://stackoverflow.com/questions/66855252/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix `undefined reference to \`main'` means that you have no main `program`. The other undefined references are calls to some subroutines or functions you are missing. – Vladimir F Героям слава Jan 07 '22 at 10:14
  • @VladimirF, `f77 -v` prints `/usr/bin/f77: fort77 Version 1.15` `/usr/bin/f77: No input files specified` and `f77 --version` prints `/usr/bin/f77: Illegal option: --version` – Mohammed Niyasdeen Jan 07 '22 at 10:20
  • @VladimirF, if f77 is same as calling gfortran, then why in the makefile if I put `COMPILE=f77` runs successfully and `COMPILE=gfortran` gives the error? And what about `COMPILE=f90`? – Mohammed Niyasdeen Jan 07 '22 at 10:28
  • AS Vladimir asks please edit the question to tell us the output of `f77 -v` and `f77 --version`. The output of `type f77` might be useful as well. It also looks to me as though you are compiling with gfortran, but may be linking with something else, which might be the cause of your problems. – Ian Bush Jan 07 '22 at 10:57
  • Is there a reason you're using different compilers for different files? `gfortran` can compile most Fortran standards, and using only one compiler will avoid a lot of hastle. (Also, by "Fortran 77 codes" and "Fortran 90 codes", do you mean "fixed-form Fortran" and "free-form Fortran"?) – veryreverie Jan 07 '22 at 11:02
  • @IanBush, please check the edited question with the output for `f77 -v` `f77 --version` and `type f77` – Mohammed Niyasdeen Jan 07 '22 at 11:12
  • @veryreverie, I am trying to re-run some old codes of my project team and reproduce the same results, which was produced like 10+ years ago. They were using both `COMPILE=f77` in one makefile and `COMPILE=f90` in another makefile but I am not sure why. All the files are fixed-form format with .f extensions. I – Mohammed Niyasdeen Jan 07 '22 at 11:21
  • 2
    OK, so it is actually f2c. A really, really obsolete thing. The problem is that you can only you this for Fortran 77 code, but if you need to use also Fortran 90, it is useless for you. You cannot combine it with a Fortran 90 compiler like gfortran. There *might* be options that will fix the name mangling issue you currently see, but chances are very high that this is not the last problem from such a combination, as janneb mentions. – Vladimir F Героям слава Jan 07 '22 at 11:29
  • 1
    Also note that the `f77` in your Makefile does nothave to be the same `f77` you currently have. It might have been any other compiler. It might have been the Sun compiler on Solaris or it might have been a symlink to anything else just as your `f77` is actually `fort77` which is a repackaged `f2c`. For example, on my computer, the `f77` is actually the Oracle compiler, the successor of the Sun compiler and is now actually just a wrapper to `f90` which is identical to `sunf90`. – Vladimir F Героям слава Jan 07 '22 at 11:34
  • Any Fortran compiler should handle Fortran 90 and Fortran 77 – Rob Jan 07 '22 at 15:53

2 Answers2

3

Gfortran supports Fortran 90, which is a superset of Fortran 77. Gfortran also supports several popular language extensions that were commonly used before Fortran 90.

Trying to use several different compilers to compile a single application will likely lead to problems due to different runtime libraries and different ABI's.

So, forget about fort77 and g77 and other obsolete compilers.

janneb
  • 36,249
  • 2
  • 81
  • 97
1

So to be specific. Most of the current errors you see in your post are from the missing fort77 runtime library. The code you compiled with f77 translated its open, read, write,... statements to calls to functions implemented in C in the runtime library. Eg., f_open is called where the open statement was invoked, the pow_dd function is called where some power like a**b was invoked when both a and b are double precision, pow_di is for a**i where i is an integer, and so on.

These functions are incompatible with gfortran-compiled code. The I/O part of the library is incompatible. The files opened in fort77 code cannot be used by read or write in gfortran and vice versa.

You might be able to get most of the error messages go away by linking the runtime library. Perhaps by -lf2c. However, that does not mean the code will work correctly. It might in simple cases, but it won't in general.

You should really compile everything with gfortran as janneb answered. If your code is incompatible with gfortran, it is very likely not standard conforming and will have to be fixed.

For specific advice on such possible fixes you have to create questions with the specific errors, such as How to solve the "fmt: end of file, last format: (3i10)" error? but with a full [mcve]. We really need a full code that we can test with all the necessary data it needs. The code must be also reasonably short. Be aware that isolating such small independent code is often hard work, but it is necessary.

  • thank you very much for this answer. Now, things are getting clearer to me. So what I am gonna do is to uninstall fort77 and try to compile and run everything with gfortran and solve the errors on the way. Thanks again. – Mohammed Niyasdeen Jan 07 '22 at 11:53