I am attempting to compile and link a Fortran code calling c subroutine:
Fortran code:
program adder
integer a,b
a=1
b=2
call addnums(a,b)
stop
e
You need to provide an interface body for the C function inside the specification part of the Fortran main program that tells the Fortran compiler that the name addnums is a C function. Something like:
INTERFACE
SUBROUTINE addnums(a, b) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT
IMPLICIT NONE
INTEGER(C_INT) :: a, b
END SUBROUTINE addnums
END INTERFACE
(With those compilers on that platform without special options the default kind of integer is the same as C_INT - but being explicit about the integer KIND helps protect you if compiler/platform or compile options change.)