Technical data

Fortran/C Wrapper Interface
45
Makele Considerations
make(1) contains default rules to help automate the control of wrapper
generation. The following example of a makele illustrates the use of these
rules. In the example, an executable object le is created from the les 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 les. 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 le changes. (The programmer
is responsible for placing the special comments for extcentry in the C source
as required.)
Note: Options to mkf2c can be specied when make is invoked by setting the
make variable F2CFLAGS. Also, do not create a .fc le for the modules that
need wrappers created. These les are both created and removed by make in
response to the le.o:le.fc dependency.
The makele above will control the generation of wrappers and Fortran
objects. You can add modules to the executable object le in one of the
following ways:
If the le is a native C le whose routines are not to be called from
Fortran using a wrapper interface, or if it is a native Fortran le, add the
.o specication of the nal make target and dependencies.
If the le is a C le 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 le placed in the target list. In addition, the
dependency of the .o le on the .fc le must be placed in the makele.
This dependency is illustrated in the example makele above where
callf.o depends on callf.fc.