如何在 Linux 中编译 Fortran 77 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1175897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 17:33:27  来源:igfitidea点击:

How to compile Fortran 77 files in linux?

linuxcompiler-constructionfortran

提问by chris

I need a compiler for Fortran 77 in linux.

我需要一个 linux 中的 Fortran 77 编译器。

Are there any free compilers out there that people use?

有没有人们使用的免费编译器?

I've heard about g77, but I can't find the rpm or how to install it in linux.

我听说过 g77,但我找不到 rpm 或如何在 linux 中安装它。

Thanks!

谢谢!

采纳答案by quark

GCC's Fortran compiler name has changed: g77has been replaced by gfortran, which handles Fortran 95 and possibly more recent variants.

GCC 的 Fortran 编译器名称已更改:g77已替换为gfortran,它处理 Fortran 95 和可能更新的变体。

The package in Ubuntu is called gfortran:

Ubuntu 中的软件包称为gfortran

sudo apt-get install gfortran

(or use synaptic)

(或使用突触)

The package in Fedora is called gfortran and is part of gcc, which you probably already have:

Fedora 中的包称为 gfortran,是 gcc 的一部分,您可能已经拥有:

sudo yum install gcc

(or use pirut)

(或使用pirut)

Similar searches should work for your distribution as well.

类似的搜索也适用于您的发行版。

Update:On RedHat 4.1.2 the package seems to be called gcc4-gfortran. Incidentally, you ought to be able to search for this with yum, and that may be the best answer to your question:

更新:在 RedHat 4.1.2 上,该包似乎被称为gcc4-gfortran. 顺便说一句,您应该能够使用 yum 搜索此内容,这可能是您问题的最佳答案:

yum search "*fortran*"

回答by paxdiablo

The means for getting software installed is distribution-specific. For example, in Ubuntu9, I would kick up Synaptic and do a search for Fortran or g77 (apt-get can also be used).

安装软件的方法是特定于发行版的。例如,在 Ubuntu9 中,我会启动 Synaptic 并搜索 Fortran 或 g77(也可以使用 apt-get)。

The other distributions I know little about although I've heard of yum and yast for (I think but I'm not sure) RedHat and Suse.

我对其他发行版知之甚少,尽管我听说过(我认为但我不确定)RedHat 和 Suse 的 yum 和 yast。

If it's not available through your standard package installer, you'll have to find another solution, such as:

如果它无法通过您的标准软件包安装程序获得,您将不得不寻找另一种解决方案,例如:

  • using a different Fortran; or
  • building it from the source.
  • 使用不同的 Fortran;或者
  • 从源头构建它。

That second method sounds ominous but it's really not (other than ensuring you have the right dependencies). The configure/make/install process that most source packages follow makes it remarkably easy to do in a cross-distribution manner.

第二种方法听起来不祥,但实际上并非如此(除了确保您拥有正确的依赖项)。大多数源包遵循的配置/制作/安装过程使得以交叉分发的方式进行非常容易。

Some RPMs can be found here. The GNU software is available hereor you may want to check out their mirrorsfor a faster site.

可以在此处找到一些 RPM 。GNU 软件在这里可用或者您可能想查看他们的镜像以获取更快的站点。

回答by R4cOOn

There's http://www.g95.org/that's available.

http://www.g95.org/这是可用的。

If I remember well GNU doesn't have a FORTRAN compiler but a FORTRAN preprocessor (or whatever the name for that is). It just translates your code to C and the compiles it with the C compiler. Of course performance becomes crap in the process.

如果我记得很清楚,GNU 没有 FORTRAN 编译器,而是一个 FORTRAN 预处理器(或任何名称)。它只是将您的代码转换为 C 并使用 C 编译器对其进行编译。当然,性能在这个过程中变得很糟糕。

However if you're using FORTRAN I assume it's a kind of computation project. If it's for free (not academic and not course related) you can get Intel FORTRAN compiler for free. In my experience it goes about 3-4 times faster than any free implementation.

但是,如果您使用的是 FORTRAN,我认为它是一种计算项目。如果它是免费的(与学术无关,也与课程无关),您可以免费获得英特尔 FORTRAN 编译器。根据我的经验,它比任何免费实现快 3-4 倍。

回答by Sajad Bahmani

You can also use Netbeans and make c&c++ project and make add Fortran with new .f90 file and use Netbeans tools to run and debug . before that you must install gcc and gfortran packages .

您还可以使用 Netbeans 并制作 c&c++ 项目,并使用新的 .f90 文件制作添加 Fortran 并使用 Netbeans 工具运行和调试。在此之前,您必须安装 gcc 和 gfortran 包。

回答by PTBNL

In my experience, Red Hat distributions (and those based on it) have gfortran included, but it is an option when you do the installation, so it seems probable that your system was set up without gfortran. If you have installation media, I think you should be able to install gfortran from there.

根据我的经验,Red Hat 发行版(以及基于它的发行版)包含 gfortran,但在您进行安装时它是一个选项,因此您的系统很可能是在没有 gfortran 的情况下设置的。如果您有安装媒体,我认为您应该可以从那里安装 gfortran。

Otherwise, to get the proper gfortran RPM for your system, I suggest the related rpmfind page.

否则,要为您的系统获得合适的 gfortran RPM,我建议使用相关的 rpmfind 页面

Once you get gfortran installed, I think the "-std=legacy" (quotes mine) should allow an F77 compile to work.

一旦安装了 gfortran,我认为“-std=legacy”(引用我的)应该允许 F77 编译工作。

回答by Aquarius_Girl

gcc-fortranis the package name for Fortrancompiler for openSUSE 11.x.

gcc-fortranFortran编译器的包名openSUSE 11.x

linux-y3pi: # zypper what-provides gcc-fortran
Loading repository data...                                                                                                                                                        
Reading installed packages...
S | Name        | Type    | Version | Arch   | Repository             
--+-------------+---------+---------+--------+------------------------
i | gcc-fortran | package | 4.5-4.2 | x86_64 | openSUSE-11.3-Oss      
i | gcc-fortran | package | 4.5-4.2 | x86_64 | openSUSE-11.3 11.3-1.82
v | gcc-fortran | package | 4.5-4.2 | i586   | openSUSE-11.3-Oss      
[1]+  Done                    yast2
linux-y3pi: # 

http://gcc.gnu.org/fortran/

http://gcc.gnu.org/fortran/

回答by gang

I did the following steps and worked!

我做了以下步骤并且成功了!

  1. Edit your /etc/apt/sources.list

  2. add this text in that file (/etc/apt/sources.list):

    deb http://hu.archive.ubuntu.com/ubuntu/ hardy universe
    deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy universe
    deb http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe
    deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe
    
  3. Save file

  4. Open terminal, type : sudo apt-get install fort77

  1. 编辑您的 /etc/apt/sources.list

  2. 在该文件 ( /etc/apt/sources.list) 中添加此文本:

    deb http://hu.archive.ubuntu.com/ubuntu/ hardy universe
    deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy universe
    deb http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe
    deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe
    
  3. 保存存档

  4. 打开终端,输入: sudo apt-get install fort77

回答by Nate

For Amazon Linux:

对于亚马逊 Linux:

 sudo yum --enablerepo=epel install gcc-gfortran

回答by Sturla Molden

"Quark" wrote in his answer that g77 is renamed gfortran. That is not correct.

“夸克”在他的回答中写道,g77 更名为 gfortran。那是不正确的。

g77 ang gfortran are different compilers. g77 is replacedby gfortran in the GNU compiler collection (GCC), it is not renamedgfortran.

g77 和 gfortran 是不同的编译器。g77在 GNU 编译器集合 (GCC) 中被 gfortran替换,它没有重命名为gfortran。

gfortran is a modern Fortran compiler based on the g95 compiler. g77 is abandonware. They do not share codebase. Binary files and libraries are also not compatible between g77 and gfortran, as they use different ABIs.

gfortran 是一个基于 g95 编译器的现代 Fortran 编译器。g77 是废弃软件。他们不共享代码库。g77 和 gfortran 之间的二进制文件和库也不兼容,因为它们使用不同的 ABI。

g77 is the same compiler known as f2c (which can be downloaded from Netlib), or more precisely a shell script called fc which called f2c and then cc on the output. All g77 did was to skip C as an intermediate language as it came with a speed penalty in the 1980s and early 1990s. f2c and g77 was written by the same man and are otherwise identical. With a modern CPU (long pipeline and branch prediction) and a modern C compiler (much better alias analysis), g77 gives you no advantage over the original f2c. gfortran, on the other hand, supports modern Fortran standards (Fortran 90, 95, 2003, and 2008) in addtion to the older Fortran 77 and Fortran 66 (aka FORTRAN IV), and is a clear improvement over g77 and f2c. It also generates faster code and gives us better error messages.

g77 是与 f2c 相同的编译器(可以从Netlib下载),或者更准确地说是一个名为 fc 的 shell 脚本,它在输出中调用 f2c 和 cc。g77 所做的只是跳过 C 作为中间语言,因为它在 1980 年代和 1990 年代初期带来了速度损失。f2c 和 g77 是由同一个人编写的,其他方面完全相同。使用现代 CPU(长管道和分支预测)和现代 C 编译器(更好的别名分析),g77 与原始 f2c 相比没有任何优势。另一方面,除了旧的 Fortran 77 和 Fortran 66(又名 FORTRAN IV)之外,gfortran 还支持现代 Fortran 标准(Fortran 90、95、2003 和 2008),并且是对 g77 和 f2c 的明显改进。它还可以生成更快的代码并为我们提供更好的错误消息。

g77 is binary compatible with f2c, but not with gfortran. gfortran can be forced to assume g77 ABI by passing -ff2c. This compiler option should be avoided if possible as it degrades the performance of the Fortran code.

g77 与 f2c 二进制兼容,但与 gfortran 不兼容。通过传递 -ff2c,可以强制 gfortran 使用 g77 ABI。如果可能,应避免使用此编译器选项,因为它会降低 Fortran 代码的性能。