Compiling with gfortran: undefined reference to ia

2019-01-27 04:10发布

问题:

I'm using gfortran [GNU Fortran (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7)] on a Fedora 20 x86_64 to compile a bunch of Fortran 77 code which refers to 'iargc' function in the following manner:

bin2D2nc.f:31: integer iargc,strlen1

bin2D2nc.f:32: external iargc,strlen1

bin2D2nc.f:44: i=iargc()

When the make script reaches the compilation comand bellow,

gfortran -O3 -ffixed-line-length-132 -fall-intrinsics -I/home/santiago/Install/netcdf_sam/include   -o bin2D2nc -I./SRC ./SRC/bin2D2nc.f ./SRC/hbuf_lib.f ./SRC/cape.f ./SRC/cin.f -L/home/santiago/Install/netcdf_sam/lib  -lnetcdf -L/usr/lib64 -lpthread

I receive these messages:

bin2D2nc.f:(.text+0x14): undefined reference to `iargc_'

collect2: error: ld returned 1 exit status

make: ** [bin2D2nc] Erro 1

I'm not the author of this code. As far as I know, I set up correctly the library paths in the makefile.

I have found that 'iargc' is a routine for backward compability with GNU Fotran 77, but I don't understand it deeply.

Could someone give some advise to surpass this problem?

回答1:

The problem is very similar to Fixing FORTRAN IV warning: "The number of arguments is incompatible with intrinsinc procedure, assume 'external' " but the difference is that in the other question there was an external function present and the similarity with an intrinsic was inadvertent, but you are calling the intrinsic on purpose.

The statement

EXTERNAL IARGC

meant that IARGC is an external or an intrinsic function in FORTRAN 66, but in "modern Fortran" 77 and later it means that it is an external function only.

But you need to call the intrinsic function https://gcc.gnu.org/onlinedocs/gfortran/IARGC.html .

You should use

 INTRINSIC IARGC

or even just delete IARGC from the EXTERNAL statement without adding anything else. The compiler will then stop searching for a non-existent external function and will use the intrinsic.

A final note, IARGC itself is not standard Fortran, ut it shouldn't matter here.