[英]Compile the Fortran program in Windows using gfortran
I have a Fortran program(.f) that I have written in Ubuntu Linux.我有一个 Fortran 程序(.f),我用 Ubuntu Linux 编写。 I compiled the written Fortran program in Linux by using the below command and it it successfully executed.
我使用以下命令在 Linux 中编译了编写的 Fortran 程序,并成功执行。
gfortran -o program program.f
Now I want to execute the same Fortran program in Windows 10 Can it be executed in window system?现在我想在Windows 10中执行同样的Fortran程序,在window系统中可以执行吗? If so please suggest me a way to do it.
如果是这样,请建议我一种方法。
I tried gfortran -o program program.f
in Windows command window,but it fails.我在 Windows 命令 window 中尝试了
gfortran -o program program.f
,但它失败了。
To compile Fortran code for Windows you need a Fortran compiler for Windows.要为 Windows 编译 Fortran 代码,您需要一个 Fortran 编译器用于 ZAEA23489CE3AA9B6403ZEBB28E0CDA4。 Microsoft neither provides a built-in one nor offers one for sale.
Microsoft 既不提供内置的,也不提供出售的。 Third-party compilers are available, including
gfortran
, but you'll need to install one yourself.第三方编译器可用,包括
gfortran
,但您需要自己安装一个。 If you want to use gfortran
in particular, or if you like it simply because you don't have to spend money to get it, then I would recommend obtaining it as part of mingw-w64 .如果您特别想使用
gfortran
,或者您喜欢它只是因为您不必花钱就可以得到它,那么我建议您将它作为mingw-w64的一部分来获取。 Alternatives are available from multiple vendors , some free of charge, but most for sale.替代品可从多家供应商处获得,有些是免费的,但大部分是出售的。
Note also that Windows expects executables to be named with an .exe
extenstion, so you would want to use a variation on gfortran your compilation command:另请注意,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. 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.
There is also a separate distribution of mingw-w64 that can be installed without MSYS2, but I don't recommend it, as the last files there have gcc-8.1.0, from 2018 (apart from a recent build by Ray Linn that includes the Ada, but not the Fortran compiler).还有一个单独的mingw-w64发行版,可以在没有 MSYS2 的情况下安装,但我不推荐它,因为那里的最后一个文件有 gcc-8.1.0,从 2018 年开始(除了 Ray Linn 最近的构建,其中包括Ada,但不是 Fortran 编译器)。
Another compiler that is now free is Intel Fortran: you have to install Microsoft Visual Studio Community , Intel oneAPI Base Toolkit and Intel oneAPI HPC Toolkit.另一个现在免费的编译器是 Intel Fortran:您必须安装Microsoft Visual Studio Community 、Intel oneAPI Base Toolkit 和 Intel oneAPI HPC Toolkit。 More information here .
更多信息在这里。 Available on Linux, macOS and Windows (of course, Visual Studio is needed only on Windows).
在 Linux、macOS 和 Windows 上可用(当然,Visual Studio 仅在 Windows 上需要)。 Intel oneAPI is at least partly open source , not sure about the Fortran compiler.
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. 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.