简体   繁体   中英

Compile the Fortran program in Windows using gfortran

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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