The Fortran compiler normally appends an underscore (_) to the names of subprograms appearing both at entry point definition and in calls. This convention differs from C procedures or external variables with the same user-assigned name. Almost all Fortran library procedure names have double leading underscores to reduce clashes with user-assigned subroutine names.
There are three usual solutions to the underscore problem:
In the C function, change the name of the function by appending an underscore to that name.
Use the BIND(C) attribute declaration to indicate that an external function is a C language function.
Use the f95 -ext_names option to compile references to external names without underscores.
Use only one of these solutions.
The examples in this chapter could use the BIND(C) attribute declaration to avoid underscores. BIND(C) declares the C external functions that can be called from Fortran, and the Fortran routines that can be called from C as arguments. The Fortran compiler does not append an underscore as it ordinarily does with external names. The BIND(C) must appear in each subprogram that contains such a reference. The conventional usage is:
FUNCTION ABC EXTERNAL XYZ BIND(C) ABC, XYZ |
Here the user has specified not only that XYZ is an external C function, but that the Fortran caller, ABC, should be callable from a C function. If you use BIND(C), the C function does not need an underscore appended to the function name.