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.

Linux* and macOS*:

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

Windows*:

icx /c cfunc.c
ifort myprog.for cfunc.obj 
 /link /out:myprog.exe

The icpx 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* and macOS*) or cfunc.obj (Windows*).

The ifort command compiles myprog.for and links cfunc.o (Linux* and macOS*) or cfunc.obj (Windows*) with the object file created from myprog.for to create the executable.

Additionally, on Linux* and macOS* systems, you may need to specify one or more of the following options:

// for C use:
icx -c  cmain.c
// for C++ use:
icpx -c  cmain.c
ifort -nofor_main cmain.o fsub.f90

For more information about compiling and linking Intel® Fortran and C++ programs on Windows* operating systems, and the libraries used, see Specifying Consistent Library Types.