Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Undefined reference to MAIN__ ???

paitor
Beginner
4,437 Views
Hi I might as well start by saying that Im a total newbie to programming, thus my problem might seem ridiculous to most of you.

Anyway, Im trying to compile an executable from src for the finite element code CalCulix, but constantly get the error (last lines):

ifort -warn unused -warn declarations -O2 -o ccx_1.5 ccx_1.5.o ccx_1.5.a ../../../SPOOLES.2.2/spooles.a ../../../ARPACK/libarpack_SUN4.a -lm
ccx_1.5.o: In function `main':
ccx_1.5.c:(.text+0x0): multiple definition of `main'
/opt/intel/fc/9.1.036/lib/for_main.o:./src/libfor/for_main.c:(.text+0x0): first defined here
ld: Warning: size of symbol `main' changed from 88 in /opt/intel/fc/9.1.036/lib/for_main.o to 29557 in ccx_1.5.o
/opt/intel/fc/9.1.036/lib/for_main.o: In function `main':
./src/libfor/for_main.c:(.text+0x3e): undefined reference to `MAIN__'
make: *** [ccx_1.5] Error 1

As Im using the ifort compiler I had to try to modify the make file which originally used: g77 -Warn -O

which I translated into: ifort -warn unused -warn declarations -O2

I have also tried to use the flags: -nus -names as_is

but no change. Also, as the code is partly written in c , Ive keept the old c-compiler options: cc -Wall -O -I

welll, thats it, any suggestions for a stupid newbie (by the way, Im running openSuSE 10.2 on a Dell Precision, with two dual core 2.0 MHz intel Xenon processors, if this has any importance) Thanks in advance paitor

0 Kudos
7 Replies
TimP
Honored Contributor III
4,436 Views

Does this option fit your situation?

-nofor-main do not link against Fortran main object
Used when linking Fortran objects with C main program

0 Kudos
paitor
Beginner
4,437 Views
Yes that did the trick smiley [:-)]. Thanks mate

BRP
0 Kudos
bredsj
Novice
4,437 Views
I have a similar type of problem, but unfortunately the proposed compiler option does not work for me as I am compiling for Fortran main code (all code is frottran).

/opt/intel/Compiler/11.1/072/lib/intel64/for_main.o: In function `main':

/export/users/nbtester/efi2linux_nightly/branch-11_1/20100415_000000/libdev/frtl/src/libfor/for_main.c:(.text+0x38): undefined reference to `MAIN__'

I'll appreciate some help

Thanks in advance

0 Kudos
mecej4
Honored Contributor III
4,437 Views
Please make sure that there is one (and only one) main program that has been compiled and included in the linking step. If you still have the problem, please report the command line and the error messages verbatim.
0 Kudos
bredsj
Novice
4,437 Views
Thanks for coming back.

I've solved the problem (at least for now) by using the -c compiler directive when compiling the individual subprograms:

ifort -O2 -i8 -r8 -assume byterecl -c -nodefaultlibs *.for

Then I compile the .o files:

ifort -O2 -i8 -r8 -assume byterecl *.o -o myprog

Whether this is correct only time will tell as I am debugging now.

I can confirm that my program has about 20 files with routines and only one main program.

What I gathered from the error message I got the compiler was looking for a MAIN__ program in the default directories hence the reference to ......../src/libfor/for_main.c - I have no for_main.c program and have no clue where this reference comes from.

Regards
0 Kudos
mecej4
Honored Contributor III
4,437 Views
| Then I compile the .o files:

| ifort -O2 -i8 -r8 -assume byterecl *.o -o myprog

No, there is no "compilation" being done with this command. The compiler parses the arguments given to it, notices that no source files were specified, and hands over the task to the linker. In fact, .o files result from a compilation, and cannot be compiled again because they are not Fortran source files.

| I have no for_main.c program and have no clue where this reference comes from.

The compiler run-time starts in a C main program, which does some setting up and then calls your Fortran main. The object for_main.o is part of the compiler runtime, and contains a reference to MAIN__ which, if you do not supply the object file resulting from compiling a Fortran main program, remains unsatisfied.

Given that all your source code is in Fortran, your post is a bit out of place in this thread!
0 Kudos
bredsj
Novice
4,437 Views
My apologies for posting on the wrong thread.

However, thanks anyway.
0 Kudos
Reply