chao sun wrote:
Dear friends
I compiled the Prep_sources_chem_cptec_wrf with the gfortran 4.4.0 and
encountered some error.
After I seted up the Fortran/C compilers and conducted ‘make’ the
error message as follows came out::
gfortran -o prep_chem_sources \
prep_chem_sources.a ..//utils/bin/libutils-2.0-opt.a
-I/usr/local/include -L/usr/local/lib -lnetcdf
This command line doesn't seem to have any "main Fortran program" as
a source ('.f'?) or an object ('.o') file, the 'prep_chem_sources.a'
must be an archive (for self-made objects required in the application),
the '.a' usually means a library (archive)... So it contains only
'programs' (routines/functions) which the old Fortran language marked
as 'SUBROUTINE's. The main Fortran program didn't have this row in its
beginning.
Maybe Chao Sun has no clue about the structure of a Fortran program? :)
I too had to dig the 1982 "FORTRAN Programs for Scientists and
Engineers" (for 8-bit Z80 with CP/M and MS Fortran-80) book from my
bookshelf in order to refresh my memory :(
/usr/lib/gcc/i586-redhat-linux/4.4.0/libgfortranbegin.a(fmain.o): In
function `main':
(.text+0x27): undefined reference to `MAIN__'
collect2: ld returned 1 exit status
make: *** [prep_chem_sources] Error 1
The function 'main()' in the 'libgfortran.a' calls this 'main Fortran
program' (Please see: 'libgfortran/fmain.c') :
----------------- clip -------------------
/* The main Fortran program actually is a function, called MAIN__.
We call it from the main() function in this file. */
void MAIN__ (void);
/* Main procedure for fortran programs. All we do is set up the environment
for the Fortran program. */
int
main (int argc, char *argv[])
{
/* Store the path of the executable file. */
store_exe_path (argv[0]);
/* Set up the runtime environment. */
set_args (argc, argv);
/* Call the Fortran main program. Internally this is a function
called MAIN__ */
MAIN__ ();
/* Bye-bye! */
return 0;
}
----------------- clip -------------------
So the executable should start at the C function 'main()' in the
'libgfortran.a', then call 'MAIN__()' (in the user-made main Fortran
program) and finally return. Nothing unexpected...
I seted up the gfortran as follows:
F_COMP=gfortran
C_COMP=gcc
LOADER=gfortran
C_LOADER=gcc
LIBS=-L/usr/local/lib -L/usr/lib -L/usr/lib/gcc/i586-redhat-linux/3.4.6
MOD_EXT=mod
# Compiler options
F_OPTS=-fconvert=big-endian -ffree-form $(NCDF_LIBS) -g
C_OPTS=-O2 -DMAIN__=main_
Why this definition for 'MAIN__' as 'main_() ? Does the
'prep_chem_sources.a' include the function 'main_()'? What is the logic
with this?
This definition maybe should be used when producing the
'libgfortran.a', then the 'main()' there would call 'main_()',
not 'MAIN__()'...