www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/30/21:40:19

Date: Wed, 1 Oct 1997 08:38:54 +0700 (GMT)
From: Alexey Yakovlev <jack AT catalysis DOT nsk DOT su>
To: Mike Kretlow <kretlow AT hrz DOT uni-siegen DOT d400 DOT de>
cc: djgpp AT delorie DOT com
Subject: Re: Calling fortran subrotuines from C
In-Reply-To: <343147a1.399544@news.uni-siegen.de>
Message-ID: <Pine.GSO.3.96.SK.971001083119.29126A-100000@quant.catalysis.nsk.su>
MIME-Version: 1.0

On Tue, 30 Sep 1997, Mike Kretlow wrote:

> I have some f77 subroutines, which I like to call from my c program.
> I compiled the file sub.f with g77 under dos and the main c-program
> with djgpp 2, but the linker couldn't find the subroutines (I declared
> them of course as extern).

 Normally, g77 (and many other compilers) names its subroutines in
lowercase letters appending an underscore to the name. Example:  
 in FORTRAN

      SUBROUTINE SUB1(A,B,C)
      DOUBLEPRECISION A
      INTEGER B
      CHARACTER*(*) C
      END

It can be called from C like this

main()
{
 double a_c;
 int b_c;
 char c_c[80];
 
 sub1_( &a_c, &b_c, c_c, 80 ); // The last parameter is the length of the
                               // string c_c
}


Alexey

================================================================
Alexey Yakovlev, Quantum Chemistry Lab.
Boreskov Institute of Catalysis, Russian Academy of Sciences
pr. Lavrentieva 5, 630090 Novosibirsk, Russia
phone: +7-(3832)-350264, fax: +7-(3832)-355766 or 357687
e-mail: jack AT catalysis DOT nsk DOT su
================================================================

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019