I spent most of two days failing to get mingw-64 installed. I have removed the failed attempts and now have mingw-w64-v10.0.0 in the download file - not yet unpacked. Could someone please!! help me through the steps till and including compiling the test program at j:\x\New.f90?
You can download gcc-12.2.0-64.exe from this website
and read quick tutorial
Should I allow setup to take place here?
C:\Users\pader\gcc
Yes, or you can choose another path if you want.
Okay done, what is the next step? if I do the check on your hello world it doesn’t recognise the commands
You can use windows cmd/powershell to compile the file
,or use vscode as you IDE
both of these are not easy for beginners,you can find some videos on Youtube ,just search [fortran vscode]
For Windows users who want to use gfortran, I definitely recommend Windows-MSYS2, it’s so complete and modern, including various unix tools, CMake, GCC, OpenBLAS, HDF5, Lua …
For writing Fortran, basically, you need a text editor, which could be VSCode, and a build tool, which could be CMake or Meson. A good terminal
would be better, I like PowerShell+PSReadline+Starship.
what should I enter in the dos textbox to do as you say?
I have a test program in j:\x\trialOne.f9. I crashed my pc yesterday in all my vain attempts. I am taking no risks now.
- using
cd
command to file directory ,cd j:\x
- compile it
gfortran trialOne.f90 -o a.exe
- run it
a.exe
I am dong what euler tells me to do
gfortran is not recognised as a command
I am in c:\users\pader
maybe the last step,you reject it Add to PATH
you should add your gcc install path
to windows environment variables
how do I do that? I don’t want to crash my system like yesterday again.
I am in c:\users\pader
Setting up your OS — Fortran Programming Language (fortran-lang.org)
Fortran-lang.org has a tutorial on configuring your OS and compiler that might be helpful.
google it
To Euler
I am in c:\users\pader
I have
c:\users\pader\gcc\X86_64-W64-mingw32
You say I have a path missing, so what is next?
add c:\users\pader\gcc\bin
to system path variable
reopen cmd
if successed you should see
c:\users\pader> gfortran
gfortran: fatal error: no input files
compilation terminated.
and then
-
j:
change your path toj
-
cd x
enter directory x using -
gfortran trialOne.f90 -o a.exe
compile it -
a.exe
run it
J:>gfortran trialOne.f90 -o a.exe
‘gfortran’ is not recognized as an internal or external command, operable program or batch file.
J; is the directory where trialOne.f90 is located
what should I do?
I can get to: c:\users\pader\gcc\bin What then?
Please follow the last instructions by @Euler-37 about modifying the environment variable PATH
.
But first, you need to understand that your operating system (Windows) has so-called environment variables that contain useful information for it.
The PATH
variable contains a list of directories, separated by “;”.
If you type the name of a command/program in your terminal, for example gfortran
, Windows will try to find the program gfortran
in each directory listed in its variable PATH
, one after the other. If Windows does not find gfortran
in any directory, it will print an error message like “command not found”. If gfortran
is found in one of these directories, it will be executed.
If you don’t put the directory of the gfortran
executable into PATH
, you will be able to run gfortran
only in its own directory, which is not practical… Generally, you want to be able to run gfortran
from any directory where you are working. So a first step is to add its directory after a “;” at the end of the PATH
variable (just append that directory, don’t delete the other directories).
In addition to what @vmagnin wrote I will add that
c:\somedir>echo %path%
will display the current path, which needs to be changed, as described above, if it does not contain the directory where gfortran is installed.