Michael Martin
Michael Martin

Reputation: 57

How do you compile the most basic fortran program (helloworld) using gfortran an cygwin?

I've searched through these forums for an answer to this, but the people posing this question tend to have even a rudimentary understanding of fortran, gfortran, and cygwin. I'm beginning a new course that focuses on Fortran, yet I cannot start on my first assignment ("hello world") given that I can't figure out how to start the process.

I'm on Windows, I have notepad++ and cygwin installed (as well as gnuplot, though I don't think that's relevant here). Beyond that, I don't know where to start. How do I get started here?

Upvotes: 1

Views: 1801

Answers (1)

matzeri
matzeri

Reputation: 8476

Ok, step by step Cygwin Fortran(90) Hello ;-)

First in which package is the GNU Fortran compiler ? We ask the Cygwin server with cygcheck -p

$ cygcheck -p bin/gfortran
Found 8 matches for bin/gfortran
...
gcc-fortran-10.2.0-1 - gcc-fortran: GNU Compiler Collection (Fortran)
gcc-fortran-7.4.0-1 - gcc-fortran: GNU Compiler Collection (Fortran)
gcc-fortran-9.3.0-1 - gcc-fortran: GNU Compiler Collection (Fortran)
gcc-fortran-9.3.0-2 - gcc-fortran: GNU Compiler Collection (Fortran)

So after you install the latest gcc-fortran package we have

$ cygcheck -c gcc-fortran
Cygwin Package Information
Package              Version        Status
gcc-fortran          10.2.0-1       OK

$ cygcheck -l gcc-fortran |grep bin
/usr/bin/f95
/usr/bin/gfortran.exe
/usr/bin/x86_64-pc-cygwin-gfortran.exe

so the compiler you are looking for is named gfortran

As you have written your Fortran Hello program we can check its format
You need to save it as Unix LF format, not Windows CRLF one. You can use d2u to convert if needed.

$ file hello.f90
hello.f90: ASCII text

$ cat hello.f90
program hello
  implicit none
  write(*,*) 'Hello world!'
end program hello

and we can now compile and run it

$ gfortran hello.f90 -o hello -Wall

$ ./hello.exe
 Hello world!

Upvotes: 2

Related Questions