Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for a Fortran 77 or newer compiler fo PC 1

Status
Not open for further replies.

ksqr

Systems Engineer
Jul 11, 2022
13
US
Hi I'm new here and hope this isn't a question beaten to death. I'm thinking about getting back into Fortran and would like to find a compiler that works on Windows 64 bit. By compiler, I mean something that compiles the source, generates binaries and then an executable. I would prefer something that does all of that without having to pass code to a C compiler or using Microsoft Visual Studio, etc. Of a course high level debugger would be important. Oh, and free (or cheap) would be great. Years ago I did lots of programming in Fortran IV, Data General Fortran 5, Fortran 77 and Lahey Fortran 77. I'd kinda like to revisit a language I really enjoyed. A major project I did was a program for data entry and graphic display of property parcel info for a large county in Arizona. Still have the source. Maybe I can get it to work again.[smile] Another language I had fun with was Algol (Data General DG/L) but we won't go there now.
 
I made a similar decision a few months ago, to attempt to resuscitate a very Fortran 4 / Fortran 77 program so it would run on a 64-bit Windows 10 computer.[ ] As per Mikrom's suggestion above, I went with GFortran, and it did the job fine.[ ] No "high level debugger" though (or not that I could find).[ ] I ported the .EXE file that GFortran produced to a 32-bit Windows 7 machine, and it worked fine "out of the box".
 
If you need a debugger, you could try the IDE Code::Blocks, where you can step through your code and watch variables.
It looks like this:

2022-07-12_18h41_11_afyxov.png


I have it on Linux, but it is available for Windows too.
 
I tried Code::Blocks on Windows. Debugging C works well, but debugging Fortran unfortunately does not work for me.
Trying to step to the next line of code i get this error
Code:
[debug]>>>>>>cb_gdb:
[debug]> next
[debug]Cannot find bounds of current function
I downloaded from here the package codeblocks-20.03mingw-nosetup.zip which contains compilers and debugger but does not require running setup - only extracting and setting path variable. So my advice is, if you want to try it, maybe try rather any other package.
 
Thanks all for the info. I installed the gfortran compiler and am using it via command line. I'm getting strange errors using gfortran -std=legacy. It looks like the compiler is building an exe by default and wants all subroutines specified. That means all modules must be specified on the command line. Any way to just compile a single module to object? Maybe another command option? My program has 61 source modules and 14 include files.
 
> Any way to just compile a single module to object?

For example these commands
[pre]gfortran -c module1.f
gfortran -c module2.f
gfortran -c module3.f[/pre]
create object files module1.o, module2.o, module3.o
and this command links then all object files together into executable program.exe
[pre]gfortran module1.o module2.o modul3.o -o program.exe[/pre]




 
I took a different approach to having a large number of code modules.[ ] I wrote a simple batch file to concatenate all the modules into the one file, compiled that composite file, then linked the resulting object file.[ ] I then deleted the single object file (but retained the composite concatenated file because it was useful for text searching purposes).
 
To build programs which consists of many sources, makefiles are used. Write once and use many times.
 
Thanks mikrom et al. The -c switch does the trick. I looked all over for that kind of info but no luck. I ask here when I hit a wall. I bet there are other switches like error output redirect. Can you point me to a document that covers this? I just found a man page for gfortran but I don't see -c in it.
 
Aha! With a little poking I found gfortran --help. The trick is two dashes... The -S switch (option) lets me keep the assembler code - yum!
 
Still don't see how to direct compiler error reporting to a file...
 
ksqr said:
Still don't see how to direct compiler error reporting to a file...
For me on Linux this works:

[pre]$ gfortran myprog.f95 -o myprog 2> compiler_errors.txt[/pre]

I currently don't have a Windows PC nearby to try it, but according to this Microsoft document it should work in windows as well. Try it.

 
Windows does support redirection of reporting of output from screen to a file, using the > operator like in Mikrom's Linux example. Using >> instead will append the output to an existing file (if one exists).
 
Hey that worked! Thanks. That business with 2 kinda rings a bell with me. Standard out & standard error? Used to manage a bunch of Unix servers back in the 90's. Been a long time. I made a batch file (macro) to compile in DOS.
echo off
gfortran -c -S -ffixed-line-length-none -std=legacy %1 2> %1.err
 
For debugging, you really need the -g switch. That adds the debug symbols.

If you're using linux or WSL with X-windows client, you could try the old ddd debugger. It is a bit dated - uses X-Motif. You move the pane sizes by using the button on the separating line.

Failing everything else, you could go back to command line debugging using gdb.

Another alternative which works on both Linux and Windows is Visual Studio Code (Microsoft Freeware) which works with gfortran.
 
> Failing everything else, you could go back to command line debugging using gdb

Funny that in the past I've only ever looked for the graphical user interface of GDB, as I always thought it would be damn difficult to learn. Now I've finally tried it, and after about an hour of hands-on debugging, I think I've already mastered the basics of GDB.
 
My old F77 source has comments on individual lines like:

DELIM = DELIM_LIST(K) ! Get delimiter

Not possible with gfortran? No big deal but if there is another magic switch, yay!
 
I have just run a small test.
My GFortran, version 6.3.0 running on a 64-bit Windows-10 computer, happily allows in-line comments that are commenced with an exclamation mark!
The only significant option I used in the compile/link operation was -static.[ ] Thus
GFORTRAN[ ] -o TestProg[ ] -static[ ] TestProg.for
 
i tried it too and everything works fine:

Code:
$ cat hello.f
      program hello
c       comment line with c in column 1
*       comment line with * in column 1
!       comment line with ! in column 1
        write (*, '(A)') 'Hello, world !' ! inline comment
      end

$ gfortran hello.f -o hello

$ ./hello
Hello, world !

$ gfortran --version
GNU Fortran (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top