This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Calling Fortran subroutines from C++
- To: Daniela De Angelis <daniela dot deangelis at mrc-bsu dot cam dot ac dot uk>
- Subject: Re: Calling Fortran subroutines from C++
- From: "Dan, Ho-Jin" <hjdan at kaist dot ac dot kr>
- Date: Sat, 27 Oct 2001 10:56:37 +0900
- CC: gcc-help at gcc dot gnu dot org
- References: <3BD985C0.5B66D356@mrc-bsu.cam.ac.uk>
for example,
--in a fortran code, fcode.f
subroutine fsubr(m,x,y)
integer m
double x(*),y(*)
.....snip....
--in a cplus code cccallsf.cc
#include "g2c.h" // see f2c
extern "C" void fsubr_(inteter*m, realdouble*x, realdouble*y); // call
by ref
// you can call fsubr_() without including g2c.h. integer -> int ,
realdouble -> double
...snip
int main()
{
integer m[1] ;
doublereal x[10], y[10];
*m = 10;
fsubr_(m,x,y);
...
}
$g77 -c fcode.f
$g++ -c cccallsf.cc
$g++ -o cccallsf cccallsf.o fcode.o -lg2c -lm
Daniela De Angelis wrote:
>I am interested in calling Fortran Subroutines from C++. Apart from the
>declaration of the Fortran
>function within my program, which I think I have sorted out, I wonder
>whether there is
>a compiling option that tells the compiler that the library I am using
>is a Fortran Library.
>I have looked for clues on the Web, with no success. I wonder whether
>you can help.
>
>Thanks
>
>--
>
>Daniela De Angelis
>MRC Biostatistics Unit Tel: + (0)1223 330390
>Institute of Public Health
>Robinson Way Fax: + (0)1223 330388
>Cambridge
>CB2 2SR Web: www.mrc-bsu.cam.ac.uk
>United Kingdom
>
>
>
>
>