Compiling and Linking Intel® Fortran/C Programs

Your application can contain both C and Fortran source files. If your main program is a Fortran source file (myprog.for) that calls a routine written in C (cfunc.c), you can use the following sequence of commands to build your application:

icc -c cfunc.c
ifort -o myprog myprog.for cfunc.o

The icc (for Intel C++) command compiles cfunc.c. The -c option specifies that the linker is not called. This command creates cfunc.o. The ifort command compiles myprog.for and links cfunc.o with the object file created from myprog.for to create myprog.

You can use the -cxxlib[-mode] compiler option to instruct the Fortran driver to add the C++ libraries to the link command. The mode argument specifies which C++ run-time libraries to use. By default, C++ libraries are not linked with Fortran applications.

You can use the -fexceptions compiler option to enable C++ exception handling table generation so C++ programs can handle C++ exceptions when there are calls to Fortran routines on the call stack. By default, mixed Fortran/C++ applications abort in the Fortran code if a C++ exception is thrown.

If your C/C++ program calls an Intel Fortran subprogram, specify the option -nofor_main on the ifort command line:

icc -c  cmain.c
ifort -nofor_main cmain.o fsub.f90