Technical data
Fortran/C Wrapper Interface
45
Makefile Considerations
make(1) contains default rules to help automate the control of wrapper
generation. The following example of a makefile illustrates the use of these
rules. In the example, an executable object file is created from the files main.f
(a Fortran main program) and callc.c:
test: main.o callc.o
f77 -o test main.o callc.o
callc.o: callc.fc
clean:
rm -f *.o test *.fc
In this program, main calls a C routine in callc.c. The extension .fc has been
adopted for Fortran-to-call-C wrapper source files. The wrappers created
from callc.fc will be assembled and combined with the binary created from
callc.c. Also, the dependency of callc.o on callc.fc will cause callc.fc to be
recreated from callc.c whenever the C source file changes. (The programmer
is responsible for placing the special comments for extcentry in the C source
as required.)
Note: Options to mkf2c can be specified when make is invoked by setting the
make variable F2CFLAGS. Also, do not create a .fc file for the modules that
need wrappers created. These files are both created and removed by make in
response to the file.o:file.fc dependency.
The makefile above will control the generation of wrappers and Fortran
objects. You can add modules to the executable object file in one of the
following ways:
• If the file is a native C file whose routines are not to be called from
Fortran using a wrapper interface, or if it is a native Fortran file, add the
.o specification of the final make target and dependencies.
• If the file is a C file containing routines to be called from Fortran using a
wrapper interface, the comments for extcentry must be placed in the C
source, and the .o file placed in the target list. In addition, the
dependency of the .o file on the .fc file must be placed in the makefile.
This dependency is illustrated in the example makefile above where
callf.o depends on callf.fc.










