Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

How to call fortran code from C++

compila
Beginner
114 Views
I've got a bunch of 3rd party *.f fortran code with some useful functions.
How to call these functions from C++?
How to generate C++ headers for these fortran functions?
Can I be sure, that such a call will be valid both on 32 an 64 bit systems?
Thanks!
________________________
Linux. Intel C++, Intel Fortran
0 Kudos
2 Replies
TimP
Black Belt
114 Views
Use of the Fortran standard iso_c_binding facility requires functions be designated with extern "C" on the C++ side. If the Fortran functions were written without iso_c_binding (Fortran 2003), the declarations would require modification accordingly. This would assure working on a variety of systems, including 32- and 64-bit (but not mixing them). Normally, the run-time libraries provided with the Fortran compiler must be linked, and they must be compatible with the C++ system you have chosen.
iso_c_binding would be a prerequisite to an automatic tool for generating C prototypes, which seems possible although I've never seen one.
The legacy alternative to iso_c_binding requires extern "C" with the function names mangled to match the scheme used by the Fortran compiler.
JenniferJ
Moderator
114 Views
Also in the documentation of Intel Fortran Compiler for Linux, there is a section "Programming using Mixed Languages" under "Building Applications".

Jennifer
Reply