using iargc()/getarg() form C

Satish Balay balay@fastmail.fm
Wed Feb 23 14:26:00 GMT 2005


On Tue, 22 Feb 2005, Steve Kargl wrote:

> On Tue, Feb 22, 2005 at 10:00:56PM -0600, Satish Balay wrote:
> > On Tue, 22 Feb 2005, Steve Kargl wrote:
> > 
> > > > Could you tell me what are the correct symbols in the fortran
> > > > library that I can call directly from C?
> > > 
> > > I just looked at the implementation of iargc.  You can't 
> > > get at the command line arguments with the gfortran
> > > functions from a C program.  Well, you might be able to
> > > get them, but we need more details in exactly what 
> > > you're doing.
> > 
> > This usage works with gcc4 with the following change:
> > iargc_  -> _gfortran_iargc
> > getarg_ -> _gfortran_getarg_i4
> 
> You don't need to do the above.
> 
> > # gcc -c arg.c
> > # gcc4 -c arg.c
> > # gfortran arg-test.f arg.o -o arg-test
> 
> This is crucial.  You must link the final program with the
> gfortran command.

Is this because of the automatic linking to -lgfortranbegin?  [we try
to detect all compiler libraries - so that any compiler c/c++/fortran
will work as the linker. sometimes this is messy and doesn't always
work]

> kargl[218] ~/gcc/work/bin/gcc -c gr.c
> kargl[219] gfc -o foo foo.f90 gr.o
> kargl[220] ./foo 1 2 3
>            3
> kargl[221] cat gr.c
> extern int  _gfortran_iargc(void);
> int iargc_(void)
> {
>   return _gfortran_iargc();
> }
> kargl[222] cat foo.f90
>         program main
>         integer i
>         i = iargc()
>         print *, i
>         end

Hmm - here you are calling iargc() from fortran. This isn't my
usage. And I thought you don't need wrappers for this usage..

# gfortran -c foo.f90
# nm foo.o
         U _gfortran_filename
         U _gfortran_iargc
         U _gfortran_ioparm
         U _gfortran_line
         U _gfortran_st_write
         U _gfortran_st_write_done
         U _gfortran_transfer_integer
00000000 T MAIN__

Satish

> I leave getargs to you to wrap.



More information about the Fortran mailing list