How do I call a Fortran routine inside a C program?
Note: For information about calling a C routine inside a Fortran program, see How do I call a C routine inside a Fortran program?
You need to keep in mind three things when calling a Fortran routine inside a C program:
- The name of the Fortran routine will be changed to all
lowercase.
- On most platforms, the name of the routine will be followed by an
underscore.
Note: This doesn't happen on the Indiana University Libra cluster.
- All arguments except array arguments need to be passed to the
Fortran subroutine as pointers (by reference).
- C stores arrays in row major while Fortran does it in column major. Therefore, when you call a Fortran subroutine in C, you need to transform the matrix before making the call.
Following is an example of calling the Fortran LAPACK routine
zgeev() from a C program, cfor.c:
You would compile and link cfor.c with the following
commands:
This document was developed with support from the National Science Foundation (NSF) under Grant No. 0503697 to the University of Chicago and subcontracted to Indiana University. Additional support was provided by IU through its participation in the TeraGrid, which is supported by the NSF under Grants No. 0833618, SCI451237, SCI535258, and SCI504075. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the NSF.
Also see:
Last modified on April 07, 2008.






