Tech and Academic things for Chianshin

Friday, June 22, 2007

Tutorial: Using C/C++ and Fortran together

Tutorial: Using C/C++ and Fortran together
C++ calling a FORTRAN function:

testC.cpp

#include

using namespace std;

extern"C" {
void fortfunc_(int *ii, float *ff);
}

main()
{

int ii=5;
float ff=5.5;

fortfunc_(&ii, &ff);

return 0;
}


testF.f
subroutine fortfunc(ii,ff)
integer ii
real*4 ff

write(6,100) ii, ff
100 format('ii=',i2,' ff=',f6.3)

return
end

Compile:

* f77 -c testF.f
* g++ -c testC.cpp
* g++ -o test testF.o testC.o -lg2c

Run: ./test

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home