Unable to run fortran on MAC

I have a MacBook Pro M1 with macOS 14.4.1, I’m trying to run a code that was send to me by my supervisor and was written and was working in windows. I’m trying to run it myself in my computer with no luck. I’ve installed gfortran using both conda and homebrew. Here I’m trying with a simple example.

In the terminal, I’ve tried:

conda activate gf
cd ~mypath

(gf) Desktop gfortran try.f90
gfortran: warning: could not understand version 14.03.00
ld: -rpath can only be used when targeting Mac OS X 10.5 or later
collect2: error: ld returned 1 exit status

Also I’ve checked the fortran version:

(gf) Desktop gfortran --version
gfortran: warning: could not understand version 14.03.00
GNU Fortran (GCC) 11.3.0

This is whats inside my .f90 file:

program hello
  print *, "Hello, Fortran!"
end program hello

I’ve tried reading the forum here and applied some of the recommendations with no luck. Can someone please help me out?

That’s a linker problem not a compiler problem. My gfortrans in both homebrew and conda report they are version 13.2. Can you deactivate your conda environment and confirm your homebrew installation status? things like which gfortran which ld and gfortran --version?

here they are with conda deactivated:

Desktop which gfortran

Desktop which ld

Desktop gfortran --version
GNU Fortran (Homebrew GCC 13.2.0) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

OK, that matches my setup. So from there what output do you get for gfortran try.f90?

Its not printing anything but generating a file in Desktop called a.out

From the Wikipedia page on a.out:

“a.out” remains the default output file name for executables created by certain compilers and linkers when no output name is specified, even though the created files actually are not in the a.out format.

$ gfortran try.f90
$ ./a.out
 Hello, Fortran!

To change the name of the executable use the -o flag, e.g.:

$ gfortran -o try try.f90

Good, as @ivanpribec notes, a.out is the name of the executable. Since you got no other output, it looks to me as if the compile and link worked. If you try to execute it ./a.out it should print the hello text from your program.

Given the error messages you originally posted, it looks as if your conda environment has a mismatching gcc for your gfortran. I am assuming you loaded the xcode command line tools correctly since this latest homebrew test seems to have worked.

Do things appear to be working for you now with homebrew?

It is working when I execute ./a.out, now if I try with a more complicated script it gives me the following:

Desktop cd /Users/lunapaluna/Desktop/dunes
dunes gfortran Unsteady_2D.f90
43 | use dflib
| 1
Fatal Error: Cannot open module file ‘dflib.mod’ for reading at (1): No such file or directory
compilation terminated.

DFLIB could be a library of the Digital Visual Fortran compiler (at the end of the 90’s).

So I won’t be able to run this script? Or is there a way to download the library so I can use it?

OK. Now you’re into areas I don’t know a lot about. dflib appears to be an old dec library of some sort. I don’t know how/if it could be replaced. It would have to be in your module search path, which you can extend with the -J switch on the gfortran command, or better yet with the fortran package manager dependency features, but first you have to find that library. It is probably worth a separate question as it’s not a gfortran issue at this point.

1 Like

Maybe but with Intel compilers:

Perhaps the procedures from dflib (assumings it’s the DEC/Intel module, and not a module from your supervisor in a different file or folder) could be replaced with open alternatives. If you modify temporarily your program like this:

program unsteady2d
! use dflib                    ! <-- temporarily comment out the module import
implicit none (type,external)  ! <-- flag external procedures
! ...

end program

you should see a number of warnings pointing to the missing procedures from dflib (and perhaps others too… :see_no_evil: ).

1 Like

An old thread from comp.lang.fortran about what is in dflib could be helpful. Does the Windows program create a GUI? Is it ok if a Mac version just writes output to the terminal or to files?

To find out what is being used from the module dflib, on Windows try compiling the program with the use dflib line commented out, and look at what names the compiler says are missing. Then create a line such as

use dflib, only: foo, bar

where foo, bar are the items imported from dflib so that the program compiles on Windows. Then you can research whether equivalents can be created for the items imported from dflib.


You could find information in Google Books, for example:

When I was using Digital Visual Fortran / Compaq Visual Fortran , I was using DFLIB for the QuickWin subroutines to build GUI. Many subroutine names were ending with QQ, like SETWSIZEQQ.

It produces some .txt files as output, so I could try removing the dependency and see what happens. I’ll ask my supervisor if she remembers how she used it. It might be faster! Thanks for the help!

1 Like