我想在C使用FORTRAN模块子程序,不能打通使用FORTRAN模块子程序,这里是我的问题的简化版本:如何在C
我有一个包含一个子程序一个FORTRAN模块,第二个子程序使用该模块。
!md.f90
module myadd
implicit none
contains
subroutine add1(a) bind(c)
implicit none
integer a
a=a+1
end subroutine add1
end module myadd
!sb.f90
subroutine sq(a) bind(c)
use myadd
implicit none
integer a
call add1(a)
a=a*a
end subroutine sq
现在我要调用的函数sb
在C:
//main.cpp
extern "C"{ void sb(int * a); }
int main(){
int a=2;
sb(&a);
}
我应该如何联系在一起?
我想是这样
ifort -c md.f90 sb.f90
icc sb.o main.cpp
,但它给错误
sb.o:在功能
sq': sb.f90:(.text+0x6): undefined reference to
ADD1' /tmp/icc40D9n7.o:在功能main': main.cpp:(.text+0x2e): undefined reference to
某人
有谁知道如何解决这个问题?
这是一个相关的问题:http://stackoverflow.com/questions/15557439/how-to-call-a-fortran90-function-included-in-a-module-in-c-code – Jason