我正在尝试从C语言中调用Fortran代码中的模块变量。我已经调用了一个子程序,但无法调用变量。
module myModule
use iso_c_binding
implicit none
real(C_FLOAT) aa(3)
contains
subroutine fortranFunction() bind(C)
print *,"hello world from Fortran 90"
aa(1)=1.0;
aa(2)=2.0;
aa(3)=3.0;
end subroutine
end module
而且这段代码是用C语言编写的
#include "stdio.h"
extern void fortranfunction();
extern float mymodule_aa_[3];
int main()
{
printf("hello world from C\n");
fortranfunction();
printf("%f %f %f \n",aa[0],aa[1],aa[2]);
return 0;
}
我正在使用以下方式进行编译:
gcc -c ccode.c
gfortran -c fortrancode.f90
gcc fortrancode.o ccode.o -lgfortran -o myprogram
gcc回复“对于'aa'的引用未定义”。
aa
是如何传递的? - Kyle Kanos