[原创]gcc4.0下的gfortran
在linux基本可用后,俺尝试在gcc里面试试fortran编程:
由于fedora core 4采用的是gcc4.0
里面的fortran编译器支持f95(俺以为)了,
调试时不再是以前的:
$g77 hello.for -o hello
$./hello
了,
经研究发现,在gcc4.0里面g77不再识别了;
改为识别gfortran了,文件后缀应改为f90或f95。
如下:
$ gfortran --help
用法:gfortran [选项] 文件...
选项:
-pass-exit-codes 在某一阶段退出时返回最高的错误码
--help 显示此帮助说明
--target-help 显示目标机器特定的命令行选项
(使用‘-v --help’显示子进程的命令行参数)
-dumpspecs 显示所有内建 spec 字符串
-dumpversion 显示编译器的版本号
-dumpmachine 显示编译器的目标处理器
-print-search-dirs 显示编译器的搜索路径
-print-libgcc-file-name 显示编译器伴随库的名称
-print-file-name=<库> 显示 <库> 的完整路径
-print-prog-name=<程序> 显示编译器组件 <程序> 的完整路径
-print-multi-directory 显示不同版本 libgcc 的根目录
-print-multi-lib 显示命令行选项和多个版本库搜索路径间的映射
-print-multi-os-directory 显示操作系统库的相对路径
-Wa,<选项> 将逗号分隔的 <选项> 传递给汇编器
-Wp,<选项> 将逗号分隔的 <选项> 传递给预处理器
-Wl,<选项> 将逗号分隔的 <选项> 传递给链接器
-Xassembler <参数> 将 <参数> 传递给汇编器
-Xpreprocessor <参数> 将 <参数> 传递给预处理器
-Xlinker <参数> 将 <参数> 传递给链接器
-combine 将多个源文件一次性传递给汇编器
-save-temps 不删除中间文件
-pipe 使用管道代替临时文件
-time 为每个子进程计时
-specs=<文件> 用 <文件> 的内容覆盖内建的 specs 文件
-std=<标准> 指定输入源文件遵循的标准
-B <目录> 将 <目录> 添加到编译器的搜索路径中
-b <机器> 为 gcc 指定目标机器(如果有安装)
-V <版本> 运行指定版本的 gcc(如果有安装)
-v 显示编译器调用的程序
-### 与 -v 类似,但选项被引号括住,并且不执行命令
-E 仅作预处理,不进行编译、汇编和链接
-S 编译到汇编语言,不进行汇编和链接
-c 编译、汇编到目标代码,不进行链接
-o <文件> 输出到 <文件>
-x <语言> 指定其后输入文件的语言
允许的语言包括:c c++ assembler none
‘none’意味着恢复默认行为,即根据文件的扩展名猜测
源文件的语言
以 -g、-f、-m、-O、-W 或 --param 开头的选项将由 gfortran 自动传递给其调用的
不同子进程。若要向这些进程传递其他选项,必须使用 -W<字母> 选项.
报告程序缺陷的步骤请参见:
<URL:http://bugzilla.redhat.com/bugzilla>.
$ g77 --help
bash: g77: command not found
编译时:
在目录下编好程序hello.f90或hello.95(注意,得以f90或f95标准编写)
然后,
编译:
$gfortran hello.f90 -o hello
执行:
$./hello
即可。
至于以前的f77程序该如何调试,俺不清楚了,因为俺一直是按照f90标准编fortran程序的。
个人以为:gcc4.0以前的版本该是可以编译f77标准的程序的。
linux可以再添加gcc4.0以前的版本的。
以上均为本人自己试的,可能有重复。
google上估计也可以搜索到相关资料。 gfortran支持f77的语法吗?
回复:(FSI)gfortran支持f77的语法吗?
G77中集成了GNU的Fortran77编译器GFORTRAN集成的是GNU最新的编译器,支持Fortran95和部分Fortran2003功能 gcc4.0里面是乎没有g77这个命令了。
另外,gfortran不支持以.for为后缀的f90/f95标准的fortran程序。
例如:
program pq
implicit none
integer(kind=8)i
real(kind=8)q
open(unit=18,file='tt.dat')
do i=1,100,1
q=sin(0.01*i)
write(18,'(i5,f12.6)')i,q
enddo
end program pq
用.for为后缀时,gfortran无法编译。
用.f90/.f95则可以。
那么,以.for为后缀的f77标准的程序能否用gfortran编译,俺再试试。 经过实验,发现:
gfortran支持f77标准的fortran程序,
但是有一点:程序必须是完全是f77标准的(包括其书写格式),且得以.for为后缀。
同时,gfortran不支持f77和f90混合的书写格式。
目前基于win的fortran编译器一般都支持f77和f90混合的书写格式的,
比如compaq的6.6等。
以上为个人观点,可能有误。
另外imsl库,gfortran里面没有,的想法将其添加进去哈。 <h1 align="center">
gfortran: Using the Compiler
</h1>
<h2>Contents</h2>
<ul>
<li><a href="http://gcc.gnu.org/fortran/usage.html#intro" target="_blank" >Introduction</a></li><li><a href="http://gcc.gnu.org/fortran/usage.html#bu" target="_blank" >Basic Usage</a></li><li><a href="http://gcc.gnu.org/fortran/usage.html#ao" target="_blank" >Advanced Options</a>
<ul><li><a href="http://gcc.gnu.org/fortran/usage.html#fixed" target="_blank" >Compiling Fixed Form Sources</a></li><li><a href="http://gcc.gnu.org/fortran/usage.html#fname" target="_blank" >Compiling Files Not Named
<code>*.f9</code></a></li><li><a href="http://gcc.gnu.org/fortran/usage.html#g77" target="_blank" >Compatibility With g77</a></li><li><a href="http://gcc.gnu.org/fortran/usage.html#fend" target="_blank" >Running the Compiler front end</a></li></ul>
</li>
</ul>
<h2><a>Introduction</a></h2>
<br>
This page is meant to give a quick overview on how to use gfortran. It
is merely a substitute for a complete manual, which has not yet been
written.
</p>
<p>
Gfortran builds on GCC, and thus
shares most characteristics with it. If you know how to use GCC, there
will not be much new information for you in this document. Especially,
the options for optimization and the generation of debugging
information are not outlined here.
</p>
<h2><a>Basic Usage</a></h2>
<p>
Gfortran is used to compile a source file, <code>source.f90</code>, to
an object file, <code>object.o</code>, or an executable,
<code>executable</code>. Along the way it generates module description
files for the modules it encounters, these are named
<code><i>nameofmodule</i>.mod</code>. If a module is used, gfortran will
read from these same files.
</p>
<p>
In order to compile the source file <code>source.f90</code>,
one would run: <code>gfortran -c source.f90</code><br>
The output file will automatically be named
<code>source.o</code>. This is an object file, which cannot be executed.
</p>
<p>
Once you have compiled some source files, you can link them
together with the necessary libraries to generate an executable. This
is done as follows: <code>gfortran -o executable object1.o object2.o
...</code>, where the the executable will be named
<code>executable</code> and the <code>objectX.o</code> are object
files, whichmay have been created as above, or equally well by another
compiler from sources in a different language. If <code>-o
executable</code> is omitted, the executable will be named
<code>a.out</code> (on cygwin systems: <code>a.exe</code>). The
executable may then be executed like any other program.
</p>
<p>
One may also skip the separate compilation step, and enter a command
such as <code>gfortran -o executable source1.f90 source2.f90</code> which
will compile the source files <code>source1.f90</code> and
<code>source2.f90</code>, link and generate the executable
<code>executable</code> in one step. You can also put object files on this
command line, they will be automatically linked in during the link step.
</p>
<h2><a>Advanced Options</a></h2>
<p>
Sometimes the basic possibilities given above do not match the user's
needs. Therefore this section outlines other stuff the user might
want to know.
</p>
<h3><a>Compiling Fixed Form Sources</a></h3>
<p>
When <code>gfortran</code> is run on a file, whose name ends in
<code>.f90</code> or
<code>.f95</code>, gfortran assumes a free form source file. If that file
actually is a fixed form source file, the user has to give the
<code>-ffixed-form</code> command line option. The precise semantics
of this option, and other options relating to fixed form versus free form
input are the same as in g77, and may be found in g77's documentation.
</p>
<h3><a>Compiling Files Not Named <code>*.f9</code></a></h3>
<p>
When running <code>gfortran</code> one actually does not run the compiler,
but the compiler driver. This driver interprets the command
line options given, and hands the work off to the actual compiler,
the assembler, and the linker. By default, this compiler driver
decides by the extensions of the given file names what to do. A file
named <code>foo.c</code> is handed to the C compiler and a file named
<code>moo.f90</code> is handed to the Fortran 95 compiler, etc. To
overrule this behavior, one has to precede the filename by the argument
<code>-x <i>lang</i></code>, where <code><i>lang</i></code> is a string
identifying the requested language. For Fortran 95 this is
<code>f95</code>.
</p>
<p>
Since Fortran allows for two different kinds of input, free form
source code and fixed form source code, the compiler has to know which
kind of input it is given. The rule in place is as follows: files whose name
ends in <code>.f</code> or <code>.for</code> are assumed to be fixed
form, files whose name end in <code>.f90</code> or <code>.f95</code>
are assumed to to be free form, for other files the source form has to
be explicitly given. This may be done by the command line options
described above, which may also be used to override these rules.
</p>
<h3><a>Compatibility with g77</a></h3>
<p>
In order to efficiently implement the passing of array sections,
binary compatibility to Fortran 77 had to be abandoned. If the user
wishes to link his sources with old Fortran 77 codes, the command line
option <code>-fg77-calls</code> changes back to the old calling
convention used by g77.
</p>
<p>
When linking with code compiled by g77, one also has to take care, because
g77 and gfortran use different libraries. Especially I/O might get messed
up due to this. Your safest bet is to only use I/O in either the g77 compiled
parts or the gfortran compiled parts, but not both, and to use the compiler
driver of the part which uses I/O in the final link step. There might be
circumstances where doing I/O in both works, but there is nothing
guaranteed. In the final link step you should also explicitly specify
the libraries of both compilers, i.e. <code>-lgfortran</code> for gfortran,
<code>-lg2c</code> for g77.
</p>
<h3><a>Running the Compiler Frontend</a></h3>
<p>
One may use gfortran as a syntax checker (or verify that gfortran's frontend
correctly accepts or rejects a program), by specifying
<code>-fsyntax-only</code> on the command line. Gfortran will then not
generate object files.
</p>
<p>
When given the command line option <code>-fdump-parse-tree</code>,
gfortran will print a representation of the parsed program, detailing both
the data objects and the executable statements of the program in a
Lisp-inspired notation. One remark for Fortran old timers:
<code>ASSIGN</code> in these dumps does not refer to the
<code>ASSIGN</code> statement, but to the operation of assignment,
i.e. sloppily speaking, the <code>=</code> operator.
</p>
<hr>
<p>Please send FSF & GNU inquiries & questions to
<a href="mailtgnu@gnu.org" target="_blank" >gnu@gnu.org</a>.
There are also <a href="http://www.gnu.org/home.html#ContactInfo" target="_blank" >other ways
to contact</a> the FSF.</p>
<p>These pages are maintained by
<a href="http://gcc.gnu.org/about.html" target="_blank" >the GCC team</a>.</p>
<address>For questions related to the use of GCC, please consult these web
pages and the <a href="http://gcc.gnu.org/onlinedocs/" target="_blank" >GCC manuals</a>. If
that fails, the <a href="mailtgcc-help@gcc.gnu.org" target="_blank" >gcc-help@gcc.gnu.org</a>
mailing list might help.<br>
Please send comments on these web pages and the development of GCC to our
developer mailing list at <a href="mailtgcc@gnu.org" target="_blank" >gcc@gnu.org</a>
or <a href="mailtgcc@gcc.gnu.org" target="_blank" >gcc@gcc.gnu.org</a>.All of our lists
have <a href="http://gcc.gnu.org/lists.html" target="_blank" >public archives</a>.
</address>
<p>Copyright (C) Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110, USA.</p>
<p>Verbatim copying and distribution of this entire article is
permitted in any medium, provided this notice is preserved.</p>
<!-- IGNORE DIFF -->Last modified 2005-07-11 另外有更多相关链接:
http://www.ifremer.fr/ditigo/molagnon/fortran90/engfaq.html
内容丰富。
google系好咚咚。
F90 FAN's : Fortran 90 Frequently
Asked about News.
Michel Olagnon's Fortran 90 List
A Fortran 90 set of pointers.
Last updated - September, 2005 初步查阅了以上资料,
对以前的观点更正如下:
gfortran支持对以.f90/.f95为后缀的f77标准的程序的编译,
如:
gfortran -ffixed-form -o q1ex q1.f95
(其中,q1.f95为源文件,q1ex为生成的可执行文件) 各个版本的gcc下的manual:
http://gcc.gnu.org/onlinedocs/
ps,gfortran的manual
回复:(linqus)[原创]gcc4.0下的gfortran
呵呵,打算开专题? 不是的,只是搜集了一下资料,呵呵,<br>网络不好,贴子发重了,<br>
过会俺编辑一下,将重复的东西换换。<br>
注意:<br>
gcc4.0中的gfortran不是完全支持f95标准的,这一点在gcc4.0.2的gfortran manual中有说明,编程时要注意
。<br>
<br>
The gfortran command supports all the options supported by the gcc
command. Only options specific to gfortran are documented here.<br>
<font size="3">Gfortran
is not yet a fully conformant Fortran 95 compiler. It can generate code
for most constructs and expressions, but work remains to be done. In
particular, there are known deficiencies with ENTRY, NAMELIST, and
sophisticated use of MODULES, POINTERS and DERIVED TYPES.</font>
For those whose Fortran codes conform to either the Fortran 77 standard
or the GNU Fortran 77 language, we recommend to use g77 from GCC 3.4.
We recommend that distributors continue to provide packages of g77-3.4
until we announce that gfortran fully replaces g77. The gfortran
developers welcome any feedback on user experience with gfortran at
fortran@gcc.gnu.org.<br>
See section “GCC Command Options” in Using the GNU Compiler Collection (GCC),<br>
for information on the non-Fortran-specific aspects of the gcc command (and, therefore,<br>
the gfortran command).<br>
All gcc and gfortran options are accepted both by gfortran and by gcc (as well as<br>
any other drivers built at the same time, such as g++), since adding gfortran to the gcc<br>
distribution enables acceptance of gfortran options by all of the relevant drivers.<br>
In some cases, options have positive and negative forms; the negative form of ‘-ffoo’<br>
would be ‘-fno-foo’. This manual documents only one of these two forms, whichever one<br>
is not the default.<br>
<br>
<br>
<br>
另外:<br>
Linux操作系统下的fortran编译器(form:http://zh.wikipedia.org/wiki/FORTRAN):
<ul>
<li>PGI Fortran</li><li>G77,GNU的Fortran77编译器,集成在GCC中。</li><li>GFORTRAN,GNU的最新的Fortran编译器,集成在GCC 4.0中,目的是支持Fortran95和一部分Fortran2003的功能,以替代G77。将于<a href="http://zh.wikipedia.org/wiki/2005%E5%B9%B4" target="_blank" >2005年</a>发布。</li><li>Intel Fortran</li><li>Absoft Fortran</li><li>g95,跟GFORTRAN同为开放源代码的Fortran95编译器。</li>
</ul>
现在intel的fortran编译器好象不错,还有linux下的free版,可以在intel的官方网站下载,并获得license。<br>
<br><br>
页:
[1]