gfortran

Compiling error with gfortran


I am trying to learn fortran90/95 for a class on vector and parallel scientific computation. I'm working on Windows Vista 32 bit and I downloaded (what I believe to be, anyway) the version of the gfortran compiler for my operating system from here.

To test if it was working, I wrote a hello world program as follows:

program testfortran
    write(*,*) 'Hello world!"
end program testfortran

pretty much verbatim from a fortran tutorial. When I try to compile it:

gfortran testfortran.f90

it gives me the following response:

C:\Program files\gfortran\bin/1d.exe: cannot open output file a.exe: Permission denied
collect2.exe: error: 1d returned 1 exit status

As an engineer, pretty much all of my programming experience has been with interpreted languages like Matlab and I'm not very familiar with compiled languages. I don't know if I'm just making a really dumb error or what. Any help would be greatly appreciated.


Solution

  • The a.exe: Permission denied message implies that you don't have permission to write to the current directory. What directory is testfortran.f90 in? Can you create a file in the same directory (say, echo hello > hello.txt)? Can you try it in a different directory? (It does seem odd, though; if you can create testfortran.f90 in that directory, you should be able to create a.exe in the same directory.)

    Or perhaps, there's already an a.exe file in that directory, and you don't have permission to overwrite it. Try

    gfortran testfortran.f90 -o testfortran.exe
    

    Also, your error message refers to 1d.exe. I would expect it to be ld.exe, the linker. And your sample program has mismatched quotation marks: 'Hello world!". It's best to copy-and-paste your source code and any error messages rather than re-typing them.