Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Installing Fortran on Mac

750 views
Skip to first unread message

Christian Opp

unread,
Mar 2, 2023, 3:15:49 PM3/2/23
to
Hello,
I'm new to Fortran and have been trying to install it on MacOS, without success. I have installed XCode, and command line developer tools and gfortran. However, Fortran does not show up as a language in XCode.

I would greatly appreciate any help.
Thanks,
Christian

gah4

unread,
Mar 2, 2023, 6:46:55 PM3/2/23
to

> I'm new to Fortran and have been trying to install it on MacOS, without success.
> I have installed XCode, and command line developer tools and gfortran.

Some years, I tried to install it on Linux, but it didn't work.
You have to install four different packages, and not all installed.

But when I installed on OS X, after installing Xcode, it just worked.

It worked so easily that I don't know what to say, other than that I followed
the instructions given.

David Bourne

unread,
Mar 3, 2023, 11:30:26 AM3/3/23
to
gfortran doesn't seem to be supported in Xcode. I've seen some attempts to include it but nothing that works. Installing Xcode and command line files probably installs libraries etc. that the gfortran maintainers rely on.

You need to use another approach. I use BBEdit to create the source code files and a make file when I need to compile a multi-file program.

For a simple one file program use a text editor to create the .f or .f90 file and compile with

gfortran bubble_sort.f -o bubble_sort

and run it with ./bubble_sort

BTW, bubble_sort.f was created using ChatGPT with the query 'write a bubble sort program for f77 using gfortran' ;-)

gah4

unread,
Mar 3, 2023, 5:35:31 PM3/3/23
to
On Friday, March 3, 2023 at 8:30:26 AM UTC-8, David Bourne wrote:

(snip)

> gfortran doesn't seem to be supported in Xcode. I've seen some attempts to include
> it but nothing that works. Installing Xcode and command line files probably installs
> libraries etc. that the gfortran maintainers rely on.

I believe this is the one that I followed:

https://gcc.gnu.org/wiki/GFortranBinariesMacOS

and yes, it needs developer tools and command line developer tools.

Ron Shepard

unread,
Mar 4, 2023, 10:30:33 AM3/4/23
to
On 3/2/23 2:15 PM, Christian Opp wrote:
> Hello,
> I'm new to Fortran and have been trying to install it on MacOS, without success. I have installed XCode, and command line developer tools and gfortran. However, Fortran does not show up as a language in XCode.
>
> I would greatly appreciate any help.
> Thanks,
> Christian

I have installed gfortran using the fink package manager for the last
20+ years. The instructions are at the fink download page.

https://www.finkproject.org/download/srcdist.php

You do not need the entire Xcode package (which is now some 40GB in
size), you just need the command line tools.

However, lately since MacOS 11, and especially since the introduction of
Apple arm64 hardware, I have been using Homebrew.

https://brew.sh

Here you also do not need the full Xcode, just the command line tools.
If you just follow the instructions, it works.

I also use the intel compiler on Macs with intel hardware. The "classic"
compiler is still supported by intel on MacOS, but the new ifx compiler
is not.

I have also recently installed the NAG compiler successfully on MacOS.

https://www.nag.com/content/nag-fortran-compiler

It works well with new codes, but it does not compile all of my legacy
codes. I don't hold that against NAG, some of those old codes have
nonstandard extensions dating from the 1970s.

$.02 -Ron Shepard

David Duffy

unread,
Mar 5, 2023, 5:13:36 PM3/5/23
to
Christian Opp <christi...@gmail.com> wrote:
> Hello,
> I'm new to Fortran and have been trying to install it on MacOS,
> without success. I have installed XCode, and command line developer
> tools and gfortran. However, Fortran does not show up as a language in
> XCode.
>

I use homebrew for this, so brew install gcc.
I notice they also have simplyfortran available

Ev Drikos

unread,
Mar 5, 2023, 9:02:08 PM3/5/23
to
Hello,

IIRC, Apple dropped gradually support for Fortran in Xcode, at least, since OS X 10.9 (Mavericks).

-To use Xcode as an IDE for a project containing Fortran source code, one could choose ie the template "Other/External Build System" and provide a Makefile.

-To add a Fortran file to the project, one can choose the template "Other/Empty" and save it as "*.f90". Thereafter, Xcode understands it is Fortran source and will colour some keywords, but this is an outdated collection, just for earlier versions of Fortran (not 2018).

Yet, you can't debug in Xcode code built by gfortran 5.0 or later, as the LLVM debugger is the only option allowed now in Xcode and doesn't understand Fortran.

Hope this helps,
Ev. Drikos


PS: The info above is based on my current system, macOS Mojave (10.14) and Xcode 10.3

gah4

unread,
Mar 5, 2023, 11:55:08 PM3/5/23
to
On Sunday, March 5, 2023 at 6:02:08 PM UTC-8, Ev Drikos wrote:

(snip)

> Yet, you can't debug in Xcode code built by gfortran 5.0 or later,
> as the LLVM debugger is the only option allowed now in Xcode and doesn't understand Fortran.

Don't write programs with bugs in them!


Ev Drikos

unread,
Mar 7, 2023, 1:16:35 AM3/7/23
to
On Monday, March 6, 2023 at 6:55:08 AM UTC+2, gah4 wrote:
> On Sunday, March 5, 2023 at 6:02:08 PM UTC-8, Ev Drikos wrote:
> ..
> > Yet, you can't debug in Xcode code built by gfortran 5.0 or later,
> > as the LLVM debugger is the only option allowed now in Xcode and doesn't understand Fortran.
> Don't write programs with bugs in them!

Apparently, I wrote what restrictions a third person may expect with Xcode.

Personally, I use LLDB with gfortran-4.8.5 in Mojave, combined i.e. with my message wrapper (gfc) that allows me to see messages for compile time errors in context (line).

Thomas Koenig

unread,
Mar 7, 2023, 2:29:17 AM3/7/23
to
[x-post, F'up]

gah4 <ga...@u.washington.edu> schrieb:
Even IEFBR14 went through two versions due to bugs, or so I heard.
First, they did not clear register 15, which should contain the
return code on exit, and then they cleared the wrong one.

Now, it is believed to be bug-free.

But maybe it was different, crosssposting to alt.folkore.computers for
clarification (or different myths).

gah4

unread,
Mar 7, 2023, 4:36:21 AM3/7/23
to
On Monday, March 6, 2023 at 11:29:17 PM UTC-8, Thomas Koenig wrote:

(snip, I wrote)

> > Don't write programs with bugs in them!

> Even IEFBR14 went through two versions due to bugs, or so I heard.
> First, they did not clear register 15, which should contain the
> return code on exit, and then they cleared the wrong one.

> Now, it is believed to be bug-free.

Only the low 8 bits of R15 are used for the return code.

Early versions of OS/360 load programs on a 2K boundary, following
the boundaries of storage keys. (Until the 4K key feature.)

So until programs were not loaded on a 256 byte boundary,
it wasn't yet a bug.


0 new messages