add.f95:(.text+0x69): undefined reference to `_gfortran_transfer_real’
add.f95:(.text+0x87): undefined reference to `_gfortran_transfer_character’
add.f95:(.text+0xa4): undefined reference to `_gfortran_transfer_real’
add.f95:(.text+0xc2): undefined reference to `_gfortran_transfer_character’
add.f95:(.text+0xdf): undefined reference to `_gfortran_transfer_real’
add.f95:(.text+0xed): undefined reference to `_gfortran_st_write_done’
collect2: ld returned 1 exit status
Some Wrong with your PATH for you gcc library
OK! you are clever and has known how call fortran routines in the C progaram. Next part I show you how to call C routines in the Fortran program!
2, Fortran 调用 C 函数
编辑C源码add.c
1 #include
2
3 void add_(float *a, float *b, float *c)
4 {
5 *c = *a + *b;
6 printf(\"%f + %f = %f\\n\", *a, *b, *c);
7 }
Notes The funtion name \"add_\"
编译源代码
# gcc -o add.o -c add.c
编辑fortran 主程序main.f95,编译和执行
1 PROGRAM MAIN
2 implicit none [Page]
3 real:: i, j, k
4 !
5 ! The first fortran program
6 !
7 i = 5.0
8 j = 8.0
9 call add(i, j, k)
10 stop
11 end program MAIN
NOTE 9 line
# gfortran -o main main.f95 add.o (or f95 -o main main.f95 add.o)
# ./main
5.000000 + 8.000000 = 13.000000
OK. If you reach here, congratulations, you have learned how to call routines between C and fortran!