繁体   English   中英

使用gfortran编译Windows中的Fortran程序

[英]Compile the Fortran program in Windows using gfortran

我有一个 Fortran 程序(.f),我用 Ubuntu Linux 编写。 我使用以下命令在 Linux 中编译了编写的 Fortran 程序,并成功执行。

gfortran -o program  program.f

现在我想在Windows 10中执行同样的Fortran程序,在window系统中可以执行吗? 如果是这样,请建议我一种方法。

我在 Windows 命令 window 中尝试了gfortran -o program program.f ,但它失败了。

要为 Windows 编译 Fortran 代码,您需要一个 Fortran 编译器用于 ZAEA23489CE3AA9B6403ZEBB28E0CDA4。 Microsoft 既不提供内置的,也不提供出售的。 第三方编译器可用,包括gfortran ,但您需要自己安装一个。 如果您特别想使用gfortran ,或者您喜欢它只是因为您不必花钱就可以得到它,那么我建议您将它作为mingw-w64的一部分来获取。 替代品可从多家供应商处获得,有些是免费的,但大部分是出售的。

另请注意,Windows 期望可执行文件以.exe扩展名命名,因此您可能希望在编译命令上使用 gfortran 的变体:

gfortran -o program.exe  program.f

If you want to use gfortran on Windows, I suggest you install MSYS2 , which has a bash terminal, and a package manager that can install gcc and gfortran, as well as lapack and many other libraries.

还有一个单独的mingw-w64发行版,可以在没有 MSYS2 的情况下安装,但我不推荐它,因为那里的最后一个文件有 gcc-8.1.0,从 2018 年开始(除了 Ray Linn 最近的构建,其中包括Ada,但不是 Fortran 编译器)。

另一个现在免费的编译器是 Intel Fortran:您必须安装Microsoft Visual Studio Community 、Intel oneAPI Base Toolkit 和 Intel oneAPI HPC Toolkit。 更多信息在这里 在 Linux、macOS 和 Windows 上可用(当然,Visual Studio 仅在 Windows 上需要)。 Intel oneAPI 至少部分开源,不确定 Fortran 编译器。

MSYS2 is a much smaller package (in terms of disk pace needed), and is used by several other free projects: R (Rtools), Octave and Strawberry Perl all include parts of it, including the gcc compilers.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM