Encountering the error "undefined reference to `MAIN_'

Hello,
In the process of compiling a pretty large (and somewhat old) app, I’m encountering the error “undefined reference to `MAIN_’.” From reading other posts, the error originates from trying to link object(s) without a program if I understood correctly. The full log is almost 40k lines but the error is clearly identified in the following lines:

…/Linux_x86_64/21.7/compilers/bin/nvfortran -fPIC -O -o app1 object1.o object2.o object3.o object4.o object5.o … -L/usr/lib64 -L/opt/openmpi/lib
…/Linux_x86_64/21.7/compilers/lib/f90main.o: In function main': nvcjCgWBt7JZmVJ.ll:(.text+0x2f): undefined reference to MAIN_’
make[4]: *** [Makefile:499: app1] Error 2

Here, object1.f is supposed to be the main program and looks like:

  PROGRAM TARGET
  ...
  call subroutines
  ...
  end

with object2.f, object3.f … having the different subroutines. I’m not really sure why this compilation fails or if the fact that the files are FORTRAN77 has anything to do with the error. Any input or suggestion would be welcomed. Thanks.

From reading other posts, the error originates from trying to link object(s) without a program if I understood correctly.

Correct, this would cause this error.

Is this how object1.f is formatted? i.e. “PROGRAM” starts in the first column?

If so, this may be the problem. F77 uses fixed formatting so characters in the first column denote a comment, hence these lines would be ignored. Executable lines should start in column 7. Alternately, you can switch to using F90 style free format by using the “-Mfree” flag during compilation (not link) of the object1.f file, or rename the file “object1.f90”.

-Mat

I should have been more precise, PROGRAM starts in column 7 and so do all the other lines with commands.

I might have located the problem: It seems that the installer user ‘sed’ incorrectly and that is why it couldn’t locate the main program that had been altered (even though the subroutines were left unchanged). Making sure that the problem was with the main program saved me a bunch of time. Thanks.