Reputation:
I have a Fortran program(.f) that I have written in Ubuntu Linux. I compiled the written Fortran program in Linux by using the below command and it it successfully executed.
gfortran -o program program.f
Now I want to execute the same Fortran program in Windows 10 Can it be executed in window system? If so, please suggest me a way to do it.
I tried gfortran -o program program.f
in Windows command window, but it fails.
Upvotes: 3
Views: 22168
Reputation: 481
As of 2023, the following steps are tested successfully on a Windows 11 PC.
http://www.equation.com, provides 32 and 64-bit x86 executables for GCC version 12.1 which includes GNU Fortran, C and C++. Make a note of where it is installing the gcc. This will be useful in step 3.
Once installed, restart your PC.
Add gcc/bin
folder which contains the gcc and gfortran executables to the PATH variable in your environment variable settings
gfortran program.f -o program.exe
Upvotes: 0
Reputation:
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).
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. More information here. Available on Linux, macOS and Windows (of course, Visual Studio is needed only on Windows). Intel oneAPI is at least partly open source, not sure about the Fortran compiler.
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.
Upvotes: 2
Reputation: 180181
To compile Fortran code for Windows you need a Fortran compiler for Windows. Microsoft neither provides a built-in one nor offers one for sale. Third-party compilers are available, including gfortran
, but you'll need to install one yourself. 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. 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:
gfortran -o program.exe program.f
Upvotes: 1