# Encountering the error "undefined reference to \`MAIN\_'

**URL:** <https://forums.developer.nvidia.com/t/encountering-the-error-undefined-reference-to-main/189792>\
**Category:** Legacy PGI Compilers (archived)\
**Created:** [September 21, 2021, 9:38pm UTC](https://forums.developer.nvidia.com/t/encountering-the-error-undefined-reference-to-main/189792 "2021-09-21T21:38:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![afernandez](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@afernandez](https://forums.developer.nvidia.com/u/afernandez)\
**Post date:** [September 21, 2021, 9:38pm UTC](https://forums.developer.nvidia.com/t/encountering-the-error-undefined-reference-to-main/189792/1 "2021-09-21T21:38:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [September 21, 2021, 9:49pm UTC](https://forums.developer.nvidia.com/t/encountering-the-error-undefined-reference-to-main/189792/2 "2021-09-21T21:49:03Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![afernandez](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@afernandez](https://forums.developer.nvidia.com/u/afernandez)\
**Post date:** [September 21, 2021, 9:51pm UTC](https://forums.developer.nvidia.com/t/encountering-the-error-undefined-reference-to-main/189792/3 "2021-09-21T21:51:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![afernandez](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@afernandez](https://forums.developer.nvidia.com/u/afernandez)\
**Post date:** [September 22, 2021, 12:52am UTC](https://forums.developer.nvidia.com/t/encountering-the-error-undefined-reference-to-main/189792/4 "2021-09-22T00:52:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TomNVIDIA](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/tomnvidia/32/14181_2.png) [@TomNVIDIA](https://forums.developer.nvidia.com/u/TomNVIDIA)\
**Post date:** [October 12, 2021, 4:06pm UTC](https://forums.developer.nvidia.com/t/encountering-the-error-undefined-reference-to-main/189792/5 "2021-10-12T16:06:46Z")

</div>

Closed on October 12, 2021, 4:06pm UTC


