Visible to Intel only — GUID: GUID-890E0199-70F5-4027-A12E-A907B4F76409
Visible to Intel only — GUID: GUID-890E0199-70F5-4027-A12E-A907B4F76409
Compile and Link Intel® Fortran and C/C++ Programs
Your application can contain both C/C++ and Fortran source files.
Use the Fortran Driver to Link Mixed Fortran and C/C++ Programs
If your main program is a Fortran source file (myprog.f90) that calls a routine written in C (cfunc.c), you can use the following sequence of commands to build your application using the Fortran driver to link mixed Fortran and C/C++ programs.
Linux
icx -c cfunc.c ifx -o myprog myprog.f90 cfunc.o
Windows
icx /c cfunc.c ifx myprog.f90 cfunc.obj /link /out:myprog.exe
The icx command for Intel® C++ or the cl command (for Microsoft Visual C++) compiles cfunc.c. The -c (Linux) or /c (Windows) option specifies that the linker is not called. This command creates cfunc.o (Linux) or cfunc.obj (Windows).
The ifx command compiles myprog.f90 and links cfunc.o (Linux) or cfunc.obj (Windows) with the object file created from myprog.f90 to create the executable.
Additionally, on Linux systems, 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++ runtime libraries. 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 contains the main() entry point and is calling an Intel® Fortran subprogram, as shown in the following:
- For C use:
icx -c cmain.c ifx -nofor_main cmain.o fsub.f90
- For C++ use:
icpx -c cmain.c ifx -nofor_main cmain.o fsub.f90
- For C use:
Use the C/C++ Driver to Link Mixed Fortran and C Programs
If your main program is a Fortran source file (fortrancallsycl.f90) that calls a routine written in C++ (array_example_sycl.cpp), you can use the following sequence of commands to build your application using the C/C++ driver to link mixed Fortran and C/C++ programs.
Linux
ifx -c fortrancallsycl.f90 -o fortrancallsycl.o icpx -fortlib -fsycl -fsycl-targets=nvptx64-nvidia-cuda array_example_sycl.cpp fortrancallsycl.o -o array_example_fortran_sycl
Windows
ifx /c fortrancallsycl.f90 /Fo:fortrancallsycl.obj icpx -fsycl -fsycl-targets=spir64 array_example_sycl.cpp fortrancallsycl.obj /Fe:array_eample_fortran_sycl.exe
The ifx command for Intel® Fortran compiles fortrancallsycl.f90. The -c (Linux) or /c (Windows) option specifies that the linker is not called. This command creates fortrancallsycl.o (Linux) or fortrancallsycl.obj (Windows).
The icpx command compiles array_example_sycl.cpp and links array_example_sycl.o (Linux) or array_example_sycl.obj (Windows) with the object file created from fortrancallsycl.f90 to create the executable.
Additionally, on Linux systems, you may need to specify one or more of the following options:
Use the -fortlib compiler option to tell the compiler to link using the Fortran runtime libraries. By default, Fortran libraries are not linked with C/C++ 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.
For more information about compiling and linking Intel® Fortran and C++ programs on Windows operating systems, and the libraries used, see Specify Consistent Library Types.