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.
Linux* OS and Mac OS* X:
icc -c cfunc.c ifort -o myprog myprog.for cfunc.o
Windows* OS:
icl /c cfunc.c ifort myprog.for cfunc.obj /link /out:myprog.exe
The icc or icl command for Intel® C++ or the cl command (for Microsoft Visual C++*) compiles cfunc.c. The -c or /c option specifies that the linker is not called. This command creates cfunc.o (Linux OS and Mac OS X) or cfunc.obj (Windows OS).
The ifort command compiles myprog.for and links cfunc.o (Linux OS and Mac OS X) or cfunc.obj (Windows OS) with the object file created from myprog.for to create the executable.
Additionally, on Linux OS and Mac OS X, you may need to specify one or more of the following options:
Use the -cxxlib compiler option to tell the compiler to link using the C++ run-time libraries provided by gcc. By default, C++ libraries are not linked with Fortran applications.
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. This option causes additional information to be added to the object file that is required during C++ exception handling. By default, mixed Fortran/C++ applications abort in the Fortran code if a C++ exception is thrown.
Use the -nofor_main compiler option if your C/C++ program calls an Intel Fortran subprogram, as shown:
icc -c cmain.c ifort -nofor_main cmain.o fsub.f90