[Edit, thanks to Vladimir F and eriktous for pointing out the standard requires the interface; and thus pointing out that my original (untested) solution wasn't quite right.]
The binding label (the name=
part of bind(c)
) is an identifier for the C processor, so in particular it is case sensitive and won't have gfortran-style decorations in the final symbol). However, without an interface available to it, gfortran will in CALC2
create a reference to the lower case symbol calc_
(as given in the linker output).
So, you need to let gfortran/linker know that the correct symbols. You do this by providing an interface. Also, note that the standard requires an explicit interface when bind(c)
is used - but you could get this "to work", even though not standard compliant.
An easy way to create an explicit interface would be to use modules: put the subroutines in one file with module calcs
/end module calcs
at the top/bottom. Or:
subroutine calc(...)
...
interface
subroutine calc2(...) bind(c, name='CALC2')
...
end subroutine
end interface
call CALC2(...)
end subroutine
Also, having interfaces is good, anyway, as it enables a lot of checking.
Alternatively, change the binding labels to lower case and append an underscore. This may well work, but is outside the standard and implementation-specific. Having the functions in separate files is thwarting the compiler's chances to detect the error.