Undefined Reference to Main error

Undefined Reference to Main error

Greetings,

I am obtaining the following error when attempting to build my code.  (Note this is all created by a separate executable)

mpif90 -D"FFTW3=1" -D"PARALLEL=0" -g -WB -traceback -debug all -warn all -mcmodel=medium -o ifc_ibm.exe "" -lfftw3 "" -lm "" -L/home/ejmurphy/FFTW_IFC/lib ""
ifort: warning #10315: specifying -lm before files may supercede the Intel(R) math library and affect performance
ifort: warning #10315: specifying -lm before files may supercede the Intel(R) math library and affect performance
/opt/intel/composer_xe_2013.5.192/compiler/lib/intel64/for_main.o: In function `main':
/export/users/nbtester/efi2linux_nightly/branch-13_0gt/20130608_000000/libdev/frtl/src/libfor/for_main.c:(.text+0x38): undefined reference to `MAIN__'
make: *** [ifc_ibm.exe] Error 1

I have read through previous threads on errors like this, so I'll clarify some stuff upfront.  The entire program, main program included, is written in fortran 90 and I am running in the current LTS of ubuntu.  I cannot seem to get past the part of my makefile that builds the dependencies for the executable.  I am a newb but I think I've gotten myself up to speed enough to understand whats going on in the makefile (though all compiler flags I don't necessarily know without a google search.)

Any help or hints would be greatly appreciated.

p.s. I added .f90 so I could attach.

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

Sorry attached.

Attachments: 

AttachmentSize
Download debug-ifc-makeflo-scal.f9017.48 KB
mecej4's picture

You have not shown the makefile nor attached any source code, but here is a guess: you probably wanted to compile more than one source file, and then link the resulting object files. If the -c option was omitted by mistake, the compiler driver (mpif90) would try to link the single object file from the first compilation and, if that source file did not contain the main program, you would see the linker error reported.

I attached it in a second post, but apparently that file is still waiting for moderator approval.

Until that file shows up.  The structure of that particular makefile appears to build dependencies first and then subsequently builds the object files, using a similar mpif90 command only with the -c option as you mentioned.

Casey's picture

Without seeing the Makefile my guess on that specifc error is that you are not listing all the dependant objects in the target for ifc_ibm.exe, specifically you are not including the object corresponding to the source file with the 'program' statement. 

On a second look, it is more than that.  I'm guessing your makefile uses a variable to list all of the objects that target depends on and you have set that variable to be empty.  In ones of those sets of empty quotes is probably where all of the objects that mecej4 is thinking about should be showing up.  Doublecheck that your makefile target depends on all of the objects it needs, and make use of the variables that are setup in your link command.  A wild guess is that one of the variables has OBJS in its name, and that same variable should be in the dependancies for your target.  Somewhere else in that file you should set this variable to be a list of all the objects that are needed for your target.  I'll update this when I can actually see your Makefile.

To illustrate what I am saying, here are some relevent lines from one of my Makefiles.

CIRCOBJS = domaincirc.o circoutput.o writehdf.o circulation.o interp3d.o circ.o
CIRCEXE = circulation
INGESTCM1 = $(INGESTLIB)/ingest_cm1.a 
all: circulation combine install 
circulation: $(CIRCOBJS) $(INGESTCM1)
 $(FC) $(CIRCOBJS) $(FFLAGS) $(INGESTCM1) $(OUTPUTINC) $(OUTPUTLIB) $(LINKOPTS) -o $(CIRCEXE)

What it looks like is happening (based on that error above) using my makefile as an analog is that CIRCOBJS is empty, which will cause none of my objects to be compiled but will run my link command at the circulation: target which would list no .o files for linking (since CIRCOBJS is empty) and will emit an error that there is no MAIN__.  

Thanks for the input Casey. I cleared out the empty library references(just references to additional libraries and mpi libraries which I am not using right now).  However, the error I am receiving remains unresolved.  And indeed, I do have the same structure for a similar element to your CIRCJOBS.  Below you can find my makefile script up until the error I am receiving, I will try and also attach the file in whole.  That is if I can actually attach it and get it posted.

# Nom du compilateur, nom de l'editeur de liens
#CC   = ifort

#LINK = ifort

# Options de compilation, options a l'edition de liens
NONEC    = -c

DEBUGC   = -c -g -WB -traceback -debug all -warn all -mcmodel=medium

OPTIMC   = -c -cm -w -O2 -extend-source -quiet -mcmodel=medium

PROFLC   = -c -u -ODEBUGR8C = -c -u -xtypemap=real:64 -g 

OPTIMR8C = -c -fast -stackvar -autopar -xtypemap=real:64PROFLR8C = -c -u -xtypemap=real:64 -O
NONEL    = 

DEBUGL   = -g -WB -traceback -debug all -warn all -mcmodel=medium

OPTIML   = -cm -w -O2 -extend-source -quiet -mcmodel=mediumPROFLL   = -u -O

DEBUGR8L = -g 

OPTIMR8L = -fast -stackvar -autopar -xtypemap=real:64PROFLR8L = -u -xtypemap=real:64 -O

# Option de redirection des objets
OPTR     = -o "MPTR     = -module "RNFLAGS=-cm -w -O2 -r8 -quiet -c 
CC = mpif90
LINK = mpif90
# --------------------------------------------------------# Parametres for Makefile # --------------------------------------------------------
# Repertoire des fichiers sources
DSR = .
# Repertoire des objets pour les fichiers sources# qui ne sont pas dans le repertoire courant
DOBJ = OBJ_DEBUG_ifc_flo_scal
# Prefix pour les noms des objets
PRE  = DEBUG_ifc_
# Type -- compilation 
OPTC    = $(DEBUGC)

OPTL    = $(DEBUGL)
# Name of executable file 
EXEC = ifc_ibm.exe
# --------------------------------------------------------
DPO = $(DOBJ)/
RNO = Rn/
INCLUDE= include
FFTW_LIBS= -lfftw3
FFTW_LIBDIR= -L/home/ejmurphy/FFTW_IFC/libADD_LIBS= ""ADD_LIBDIR= ""
MPI_LIBS= ""
MPI_LIBDIR= ""
MACRO=-D"FFTW3=1" -D"PARALLEL=0"
# List the objet files
-e LOBJ = -e \-e \-e $(DPO)precision.o-e \-e $(DPO)constants.o-e \-e $(DPO)global_data.o-e \-e $(DPO)scalar_data.o-e \-e $(DPO)general_funcs.o-e \-e $(DPO)string_funcs.o-e \-e $(DPO)randomno.o-e \-e $(DPO)postproc_funcs.o-e \-e $(DPO)hard_coll.o-e \-e $(DPO)functions.o-e \-e $(DPO)interpolation.o-e \-e $(DPO)machine.o-e \-e $(DPO)errormesgs.o-e \-e $(DPO)fftw_interface.o-e \-e $(DPO)initialize.o-e \-e $(DPO)workarrays.o-e \-e $(DPO)tridiagonal.o-e \-e $(DPO)gauss_seidel.o-e \-e $(DPO)restart_funcs.o-e \-e $(DPO)dem_mod.o-e \-e $(DPO)dependent_functions.o-e \-e $(DPO)soft_sphere_coll.o-e \-e $(DPO)collision_mod.o-e \-e $(DPO)maternmod.o-e \-e $(DPO)geom_init.o-e \-e $(DPO)scalar_init.o-e \-e $(DPO)initialize_flo.o-e \-e $(DPO)boundary_condition.o-e \-e $(DPO)nl_allflow.o-e \-e $(DPO)nl_allflow_noncons.o-e \-e $(DPO)nl.o-e \-e $(DPO)poisson.o-e \-e $(DPO)usteptime.o-e \-e $(DPO)steptheflow.o-e \-e $(DPO)writeoutput.o-e \-e $(DPO)bc_scalar.o-e \-e $(DPO)nl_allphi.o-e \-e $(DPO)nlphi.o-e \-e $(DPO)stepthescalar.o-e \-e $(DPO)outputscalar.o-e \-e $(DPO)mypost.o-e \-e $(DPO)dtibm_main_scal_flo.o

-e RNOBJ = -e \-e \-e $(DPO)ranu2.o-e \-e $(DPO)rann2.o-e \-e $(DPO)vrand.o-e \-e $(DPO)ransed.o-e \-e $(DPO)ranstd.o-e \-e $(DPO)ranjn.o
# Construction of Dependencies for the executable
$(EXEC) : $(RNOBJ) $(LOBJ)

$(LINK) $(MACRO) $(OPTL)  -o $(EXEC) $(RNOBJ) $(LOBJ) $(FFTW_LIBS) -lm $(FFTW_LIBDIR)

Seeing if attaching the makefile works the second time.

Attachments: 

AttachmentSize
Download debug-ifc-makeflo-scal.f9017.48 KB
Casey's picture

I took a look at your makefile (the one attached in the post above) and the major problem I found with it was many of your lines (e.g. line 82 - 124) had "-e" at the beginning and immediately before the line continuation character.  Those all have to go.  Aside from that issue, I don't see any obvious problems.   If I cleanup all of the extranous "-e" instances in your makefile and simulate your filestructure the makefile acts as it should and I end up with (note I switched the compiler, but that is not of consequence):

mpiifort -D"FFTW3=1" -D"PARALLEL=0" -g -WB -traceback -debug all -warn all -mcmodel=medium -o ifc_ibm.exe OBJ_DEBUG_ifc_flo_scal/precision.o OBJ_DEBUG_ifc_flo_scal/constants.o OBJ_DEBUG_ifc_flo_scal/global_data.o OBJ_DEBUG_ifc_flo_scal/scalar_data.o OBJ_DEBUG_ifc_flo_scal/general_funcs.o OBJ_DEBUG_ifc_flo_scal/string_funcs.o OBJ_DEBUG_ifc_flo_scal/randomno.o OBJ_DEBUG_ifc_flo_scal/postproc_funcs.o OBJ_DEBUG_ifc_flo_scal/hard_coll.o OBJ_DEBUG_ifc_flo_scal/functions.o OBJ_DEBUG_ifc_flo_scal/interpolation.o OBJ_DEBUG_ifc_flo_scal/machine.o OBJ_DEBUG_ifc_flo_scal/errormesgs.o OBJ_DEBUG_ifc_flo_scal/fftw_interface.o OBJ_DEBUG_ifc_flo_scal/initialize.o OBJ_DEBUG_ifc_flo_scal/workarrays.o OBJ_DEBUG_ifc_flo_scal/tridiagonal.o OBJ_DEBUG_ifc_flo_scal/gauss_seidel.o OBJ_DEBUG_ifc_flo_scal/restart_funcs.o OBJ_DEBUG_ifc_flo_scal/dem_mod.o OBJ_DEBUG_ifc_flo_scal/dependent_functions.o OBJ_DEBUG_ifc_flo_scal/soft_sphere_coll.o OBJ_DEBUG_ifc_flo_scal/collision_mod.o OBJ_DEBUG_ifc_flo_scal/maternmod.o OBJ_DEBUG_ifc_flo_scal/geom_init.o OBJ_DEBUG_ifc_flo_scal/scalar_init.o OBJ_DEBUG_ifc_flo_scal/initialize_flo.o OBJ_DEBUG_ifc_flo_scal/boundary_condition.o OBJ_DEBUG_ifc_flo_scal/nl_allflow.o OBJ_DEBUG_ifc_flo_scal/nl_allflow_noncons.o OBJ_DEBUG_ifc_flo_scal/nl.o OBJ_DEBUG_ifc_flo_scal/poisson.o OBJ_DEBUG_ifc_flo_scal/usteptime.o OBJ_DEBUG_ifc_flo_scal/steptheflow.o OBJ_DEBUG_ifc_flo_scal/writeoutput.o OBJ_DEBUG_ifc_flo_scal/bc_scalar.o OBJ_DEBUG_ifc_flo_scal/nl_allphi.o OBJ_DEBUG_ifc_flo_scal/nlphi.o OBJ_DEBUG_ifc_flo_scal/stepthescalar.o OBJ_DEBUG_ifc_flo_scal/outputscalar.o OBJ_DEBUG_ifc_flo_scal/mypost.o OBJ_DEBUG_ifc_flo_scal/dtibm_main_scal_flo.o OBJ_DEBUG_ifc_flo_scal/ranu2.o OBJ_DEBUG_ifc_flo_scal/rann2.o OBJ_DEBUG_ifc_flo_scal/vrand.o OBJ_DEBUG_ifc_flo_scal/ransed.o OBJ_DEBUG_ifc_flo_scal/ranstd.o OBJ_DEBUG_ifc_flo_scal/ranjn.o "" -lfftw3 "" -lm "" -L/home/ejmurphy/FFTW_IFC/lib ""
/opt/intel/composer_xe_2013.5.192/compiler/lib/intel64/for_main.o: In function `main':
/export/users/nbtester/efi2linux_nightly/branch-13_0gt/20130608_000000/libdev/frtl/src/libfor/for_main.c:(.text+0x38): undefined reference to `MAIN__'
make: *** [ifc_ibm.exe] Error 1

In my case, that error is expected because all of my objects are empty files with no code.  If you still get that error after the Makefile produces this link line, then your error is that none of your included objects came from a source file with a PROGRAM / END PROGRAM block in it, which is where the MAIN__ function comes from.  If you don't get that error anymore after you get that link line to show up, then it was just your makefile not including all of your objects in the link. 

Will try and report back.  Also, quick question.  What does the -e option mean?  I've searched this extensively and cannot seem to find a decent explanation.  I began receiving errors when I tried to take this piece out originally.

Casey's picture

I've never seen the -e used in the Makefile like that.  I attached the Makefile I edited so you can see all of the changes I made.  

Attachments: 

AttachmentSize
Download makefile.gz2.51 KB

Thanks so much Casey.  Removing the -e options did the trick!

Login to leave a comment.