[toc]
Fortran教程
call Fortran from C:参考:https://sites.google.com/site/kaizhangstatmech/code/callfortran
fortrancode.f
1
2
3
4
5
6
7
8
9
10
11
12
13subroutine fortfunc(ii,ff)
integer ii
real*4 ff
write(6,100) ii, ff
100 format('ii=',i2,' ff=',f6.3)
return
endcppcode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using namespace std;
extern"C" {
void fortfunc_(int *ii, float *ff);
}
main()
{
int ii=5;
float ff=5.5;
fortfunc_(&ii, &ff);
return 0;
}compile as
1
2
3
4
5gfortran -c fortrancode.f
g++ -c cppcode.c
g++ -o run fortrancode.o cppcode.o -lgfortranor
1
2
3
4
5f77 -c fortrancode.f
g++ -c cppcode.c
g++ -o run fortrancode.o cppcode.o -lg2c