undefined reference to `MAIN__'

undefined reference to `MAIN__'

Hi! My system: Debian 7.4 x86_64 / Intel Fortran Composer XE for Linux 2013 SP1 Update 2 / ifort version 14.0.2

After installation Intel Fortran Composer I used:  source /opt/intel/bin/compilervars.sh intel64

I'm trying to compile my *.f files with this command:

ifort -nofor-main -O2 -r8 -extend-source 80 -warn general *.f -o myprog

but this error occurs:

/opt/intel/composer_xe_2013_sp1.2.144/compiler/lib/intel64/libifcore.a(for_main.o): In function `main':
for_main.c:(.text+0x54): undefined reference to `MAIN__'

What's wrong here? Thanks in advance! Alex.


5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Without -nofor-main i have:

/opt/intel/composer_xe_2013_sp1.2.144/compiler/lib/intel64/for_main.o: In function `main':
/export/users/nbtester/efi2linux_nightly/branch-14_0/20140121_010000/libdev/frtl/src/libfor/for_main.c:(.text+0x42): undefined reference to `MAIN__'

Since you are creating a final executable, you need to have a main program, one where the execution can start.

Either you need to have a Fortran program that is the main program, or a C program.

It does not seem like you have either in this case.


Fortran main program is one beginning with PROGRAM (or, in f66 style, no procedure name declaration).  Without it, the linker doesn't have an entry point to start the program.

You're actually telling the compiler to compile AND link.  To compile only, do:

-fort -c *.f

That will generate some *.o files.  Then, if you have a main program unit on the Fortran side (i.e., one with PROGRAM... END PROGRAM), you can link with:

ifort -o myprog *.o

If your main program unit is on the C-side, then you'll need something like:

ifort -c *.f

icc -o myprog *.c *.o

Leave a Comment

Please sign in to add a comment. Not a member? Join today