我正在尝试在 c 中使用 fortran 模块子例程并且无法通过,这是我的问题的简化版本:
我有一个包含子例程的 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
sb'
有谁知道如何解决这个问题?