Fortran 命令行编译 IVF win7

本文介绍了如何在Windows 7环境下使用Intel Visual Fortran Compiler 11.0进行命令行编译。通过批处理文件make.bat展示了编译过程,包括设置环境变量、编译源代码ex0701.f90并链接生成ex0701.exe。编译时需注意Intel编译器和Visual Studio的路径以及licences文件的位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Intel(R) Visual Fortran Compiler Professional for applications running on IA-32, Version 11.0.061

 

简单的测试函数如下:保存为exo701.f90  (取自《Fortran95程序设计【彭国伦】》的附书源码)

 

! Free Format
program main
write(*,*) "Hello" ! 这也是注解
write(*,*) &
"Hello"
wr&
&ite(*,*) "Hello"
end

 

==================================

 

命令行批处理文件如下(保存为make.bat):

 

@echo off
Rem
Rem Copyright  (C) 1985-2008 Intel Corporation. All rights reserved.
Rem
Rem The information and source code contained herein is the exclusive property
Rem of Intel Corporation and may not be disclosed, examined, or reproduced in
Rem whole or in part without explicit written authorization from the Company.
Rem

Rem Intel(R) Visual Fortran Compiler Professional Build Environment for applications running on IA-32

echo.
echo Intel(R) Visual Fortran Compiler Professional for applications running on IA-32, Version 11.0.061
echo Copyright (C) 1985-2008 Intel Corporation. All rights reserved.
echo.


@call "D:/Microsoft Visual Studio 10.0/VC/bin/VCVARS32.BAT"

SET IFORT_COMPILER11=C:/Program Files/Intel/Compiler/11.0/061/fortran

SET INTEL_LICENSE_FILE=C:/Program Files/Common Files/Intel/Licenses

 

SET PATH=%IFORT_COMPILER11%/Bin/ia32;%PATH%
SET LIB=%IFORT_COMPILER11%/Lib/ia32;%LIB%
SET INCLUDE=%IFORT_COMPILER11%/Include;%IFORT_COMPILER11%/Include/ia32;%INCLUDE%

Rem ---------======G-Spider @2011=======----------------
ifort /nologo   ex0701.f90
link  /INCREMENTAL:NO /NOLOGO  /SUBSYSTEM:CONSOLE ex0701.obj

del *.obj

ex0701.exe

pause

 

===================================

以上需要注意的是D:/Microsoft Visual Studio 10.0/VC/bin/VCVARS32.BAT

和路径C:/Program Files/Intel/Compiler/11.0/061/fortran 

C:/Program Files/Common Files/Intel/Licenses 为licence文件,请依照自己的按装更改即可。

若无licence文件intel_TBE.lic则会出现错误:

Is your license file in the right location and readable?
The location of your license file should be specified via
the $INTEL_LICENSE_FILE environment variable.

License file(s) used were (in this order):
    1.  Trusted Storage
    2.  C:/Program Files/Common Files/Intel/Licenses

 

 

双击运行批处理,如下图显示程序结果:

 

更多的编译选项请参考Intel(R) Visual Fortran Compiler User and Reference Guides

 

                         Intel(R) Fortran Compiler Help
                         ==============================

   usage: ifort [options] file1 [file2 ...] [/link linker_options]

      where options represents zero or more compiler options

      fileN is a Fortran source (.f .for .ftn .f90 .fpp .i .i90),
      assembly (.asm), object (.obj), static library (.lib), or
      other linkable file

 

      linker_options represents zero or more linker options 链接器来自vs或vc中的link.exe

 

New Options

This topic lists the options that provide new functionality in this release.

Some compiler options are only available on certain systems, as indicated by these labels:

### 配置Visual Studio 2022中的Fortran命令行编译环境 #### 安装Intel Fortran编译器 为了能够在Visual Studio 2022中配置并使用Fortran命令行编译环境,安装Intel Visual Fortran Compiler Professional版本是一个重要的前提条件[^1]。该编译器专为IA-32架构设计的应用程序提供支持。 #### 设置环境变量 确保Intel Fortran编译器的路径已添加到系统的`PATH`环境变量中。这一步骤对于能够从任何位置调用编译器至关重要。通常,在完成编译器安装过程中会自动处理此设置;如果没有,则需手动添加。 #### 创建批处理脚本简化编译过程 编写一个简单的批处理(.bat)文件可以极大地提高工作效率。下面给出了一种创建批处理文件的方法: ```batch @echo off set IFORT_COMPILER_PATH=C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\bin\ set PATH=%IFORT_COMPILER_PATH%;%PATH% ifort /c %1.f90 ifort %~n1.obj /Fe:%~n1.exe del *.obj pause ``` 上述代码片段定义了两个环境变量:一个是针对特定版本的Intel Fortran编译器目录(`IFORT_COMPILER_PATH`),另一个则是更新后的全局搜索路径(`PATH`)。接着利用`ifort`指令分别完成了源码文件(*.f90)向目标文件(*.obj)以及最终链接成可执行文件(*.exe)的过程。最后清理掉中间产生的对象文件以保持工作区整洁[^4]。 #### 测试编译环境 验证新建立起来的命令行编译环境是否正常运作的一个简单方法就是尝试编译一段经典的“Hello World!”程序。当一切顺利时,应当能观察到预期的结果——即生成名为hello.exe的可执行文件,并可通过直接运行它获得相应的输出信息:“Hello, World!”。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值