k4lls
k4lls

Reputation: 141

Fortran subroutine called from Objective-C

I am calling a fortran subroutine from a cocoa application. The application is building with success and working as expected but I have this semantic issue : *

Implicit declaration of function "_increment" is invalid in C99


Screen shot

increment.o is the compiled fortran subroutine (gfortran compiler)

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

What am I doing wrong ? Thank you for your help.

Upvotes: 1

Views: 208

Answers (1)

You have to declare the type of the function. Something like:

void increment_(int * i);

(In C, but I assume it is the same and I am guessing the correct signature, you do not show its code).

BTW, I recommend the Fortran subroutine as bind(C) or even bind(C,name="increment") and you do not have to use the trailing _.

Edit: try this

in the .m file:

void increment(int * i);

int the .f90 file:

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

If it does not help, try to use a debugger, or try some debugging print statements in the subroutine if loc(n) is equal to &i or whatever.

Upvotes: 2

Related Questions