Calling FORTRAN from C
Oleg Krivosheev
kriol@bpmail.fnal.gov
Mon Dec 4 10:01:00 GMT 2000
On Mon, 4 Dec 2000, Robert Boehne wrote:
> To call FORTRAN from C, you should declare the subroutines
> you want to call as extern "C" with their names in uppercase
you spent too much time with C++.
there is no such things as 'extern "C"' in C.
> and underscores prepended to them. For example to call
> the fortran function INTEGER NINT( INTEGER ) from C you would
> declare it as:
>
> extern "C" {
> int _NINT( int &arg1 );
> }
>
at least in Debian 2.2 the prototype would be
int nint_( int* arg );
note the small letters and underscore after the name
> A FORTRAN subroutine is just a function returning void, so it would
> be extern "C" { void _SUB1(sometype &arg1, etc...); }
nope, it would be
void sub1_( int*, double*, etc... );
>
> You can also find more details about this in the Fortran FAQ.
> In general though, you should use "nm" on your object files
> to determine the exact names the fortran compiler is giving
> the functions you create. It should be easy to do this with
> gcc/g77, some compilers make it more difficult, i.e. HP has to have
> a fortran initialization routine called before intrinsic functions
> such as "GETARG" can be used, so YMMV.
>
> Cheers!
>
> Robert Boehne
i believe it is offtopic for gcc @gcc.gnu.org, so we'd better move the
discussion to private e-mail
Robert, feel free to ask how to link Fortran and C, there are some
tricks involved in COMMON linkage and string arguments.
OK
More information about the Gcc
mailing list