Fortran子程序从Objective-C调用

时间:2013-09-03 12:43:47

标签: objective-c function fortran subroutine

我从一个可可应用程序中调用了一个fortran子例程。 应用程序正在成功构建并按预期工作但我有这个语义问题: *

  

C99

中隐含的函数声明“_increment”无效

Screen shot

increment.o是编译后的fortran子程序(gfortran编译器)

subroutine increment(n)
     integer :: n
     n=n+1
end subroutine increment

我做错了什么? 谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

您必须声明函数的类型。类似的东西:

void increment_(int * i);

(在C中,但我认为它是相同的,我猜测正确的签名,你没有显示它的代码)。

BTW,我推荐Fortran子程序为bind(C)甚至bind(C,name="increment"),你不必使用尾随_。

修改:试试这个

<。>文件中的

void increment(int * i);

在.f90文件中:

subroutine increment(n) bind(C,name="increment")
 use iso_c_binding
 integer(c_int),intent(inout) :: n
 n = n+1
end subroutine

如果它没有用,请尝试使用调试器,或者如果loc(n)等于&i或其他什么,请在子例程中尝试一些调试打印语句。