简体   繁体   English

使用gfortran编译Windows中的Fortran程序

[英]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.

相关问题 使用Windows编译Linux的Ada程序 - Compile Ada program for Linux using Windows 使用eclipse编译Fortran代码时出错...通过Linux终端使用Gfortran时可以 - Error compiling Fortran code with eclipse… it is OK when using Gfortran via Linux terminal 如何设置 linux 将 FORTRAN 代码编译成 windows 二进制文件? - How can I setup linux to compile FORTRAN code into windows binaries? 是否可以使用 gfortran 和 openmpi 在 Linux 中编译 NASA Parallel Benchmarks (NPB) 文件? - Is it possible to compile NASA Parallel Benchmarks (NPB) files in Linux using gfortran and openmpi? 在Windows下使用Ifort for Linux编译Fortran - Compiling Fortran using Ifort for Linux under Windows C程序将在Linux而非Windows上编译并运行 - C Program will compile and run in Linux but not Windows 如何在windows上运行的linux上编译c程序 - how to compile c program on linux that runs on windows 如何在Linux中使用Windows套接字编译程序? - How to compile program with windows sockets in linux? 使用popen编译外部程序 - Using popen to compile external program 最初用 Linux 编写的 C 程序,现在使用 Cygwin 移植到 Windows(使用 gcc 编译) - C program originally written in Linux, now porting to Windows using Cygwin (compile w/ gcc)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM