Mixed-Language Programming#
- Interoperability with C
- GNU Fortran Compiler Directives
- Non-Fortran Main Program
- _gfortran_set_args — Save command-line arguments
- _gfortran_set_options — Set library option flags
- _gfortran_set_convert — Set endian conversion
- _gfortran_set_record_marker — Set length of record markers
- _gfortran_set_fpe — Enable floating point exception traps
- _gfortran_set_max_subrecord_length — Set subrecord length
- Naming and argument-passing conventions
This chapter is about mixed-language interoperability, but also applies if you link Fortran code compiled by different compilers. In most cases, use of the C Binding features of the Fortran 2003 and later standards is sufficient.
For example, it is possible to mix Fortran code with C++ code as well
as C, if you declare the interface functions as extern "C"
on
the C++ side and BIND(C)
on the Fortran side, and follow the
rules for interoperability with C. Note that you cannot manipulate
C++ class objects in Fortran or vice versa except as opaque pointers.
You can use the gfortran command to link both Fortran and
non-Fortran code into the same program, or you can use gcc
or g++ if you also add an explicit -lgfortran
option
to link with the Fortran library. If your main program is written in
C or some other language instead of Fortran, see
Non-Fortran Main Program, below.