Using Intel Fortran Compiler from the Command Line
Using the Compiler and Linker from the Command Line
The ifort command is used to compile and link your programs from the command line.
You can either compile and link your projects in one step with the ifort command, or compile them with ifort and then link them as a separate step.
In most cases, you will use a single ifort command to invoke the compiler and linker.
You can use the ifort command in either of two windows:
- Your own terminal window, in which you have set the appropriate environment variables by executing the file called ifortvars.sh or ifortvars.csh (Linux* and Mac OS* X) orifortvars.bat (Windows*). This file sets the environment variables such as PATH. By default, ifortvars file is installed in the \bin directory for your compiler. For more information, see Using the ifortvars File to Specify Location of Components.
- On Windows systems, the supplied Fortran command-line window in the Intel® Fortran program folder, in which the appropriate environment variables in ifortvars.bat are preset.
The ifort command invokes a driver program that is the actual user interface to the compiler and linker. It accepts a list of command options and file names and directs processing for each file.
The driver program does the following:
- Calls the Intel® Fortran Compiler to process Fortran files.
- Passes the linker options to the linker.
- Passes object files created by the compiler to the linker.
- Passes libraries to the linker.
- Calls the linker or librarian to create the executable or library file.
You can also use ld (Linux and Mac OS X) or link (Windows) to build libraries of object modules. These commands provide syntax instructions at the command line if you request it with the /? or /helpoption.
The ifort command automatically references the appropriate Intel Fortran Run-Time Libraries when it invokes the linker. Therefore, to link one or more object files created by the Intel Fortran compiler, you should use the ifort command instead of the link command.
Because the driver calls other software components, error messages may be returned by these other components. For instance, the linker may return a message if it cannot resolve a global reference. The -watch (Linux and Mac OS X) or /watch (Windows) command-line option can help clarify which component is generating the error.
NOTE
Windows systems support characters in Unicode* (multibyte) format; the compiler will process file names containing Unicode* characters.
Using the ifortvars File to Specify Location of Components
Before you first invoke the compiler, you need to be sure certain environment variables are set. These environment variables define the location of the various compiler-related components.
The Intel Fortran Compiler installation includes a file that you can run to set environment variables.
- On Linux*and Mac OS* X, the file is a shell script called ifortvars.sh or ifortvars.csh.
- On Windows*, the file is a batch file called ifortvars.bat.
The following information is operating system-dependent.
Linux and Mac OS X:
Set the environment variables before using the compiler. You can use the source command to execute the shell script, ifortvars.sh or ifortvars.csh, from the command line to set them. For example, to execute this script file for the bash shell:
source /opt/intel/fc/10.1/bin/ifortvars.sh
If you use the C shell, use the .csh version of this script file:
source /opt/intel/fc/10.1/bin/ifortvars.csh
If you want ifortvars.sh to run automatically when you start Linux or Mac OS X, you can edit your .bash_profile file and add the line above to the end of your file. For example:
# set up environment for Intel compiler
source /opt/intel/fc/10.1/bin/ifortvars.sh
If you compile a program without ensuring the proper environment variables are set, you will see an error similar to the following when you execute the compiled program:
./a.out: error while loading shared libraries:
libimf.so: cannot open shared object file: No such file or directory
Windows:
Under normal circumstances, you do not need to run the ifortvars.bat batch file. The Fortran command-line window sets these variables for you automatically. To activate this command-line window, select Fortran Build Environment for applications... available from the Intel Fortran program folder.
NOTE
You will need to run the batch file if you open a command-line window without using the provided Build Environment for applications... menu item in the Intel Fortran program folder or if you want to use the compiler from a script of your own.
The batch file inserts the directories used by Intel Fortran at the beginning of the existing paths. Because these directories appear first, they are searched before any directories in the path lists provided by Windows. This is especially important if the existing path includes directories with files having the same names as those needed by Intel Fortran.
If needed, you can run ifortvars.bat each time you begin a session on Windows* systems by specifying it as the initialization file with the PIF Editor.
1.http://www.csbi.mit.edu/technology/intel_fce/doc/main_for/mergedProjects/bldaps_for/common/bldaps_use_cmplrcmdline.htm
2.http://www.csbi.mit.edu/technology/intel_fce/doc/main_for/mergedProjects/bldaps_for/common/bldaps_setup_envars.htm
댓글
댓글 쓰기